I am sending a POST request using POSTMAN to a route in my localhost
.
The route has been perfectly defined in my main.go
file. Moreover, it also gets triggered by sending the post request.
However, when I try to print the body, it always seems to be empty.
I tried to replicated the issue with the code below
package main
import (
"fmt"
"html/template"
"io/ioutil"
"log"
"net/http"
"path"
"strings"
)
func MeetingOperations(w http.ResponseWriter, r *http.Request) {
reqBody, _ := ioutil.ReadAll(r.Body)
fmt.Fprintf(w, "%+v", string(reqBody))
fmt.Println(string(reqBody))
fmt.Println("SCHEDULE MEETING ROUTE")
}
func handleRequests() {
http.HandleFunc("/meetings/", MeetingOperations)
log.Fatal(http.ListenAndServe(":10000", nil))
}
func main() {
handleRequests()
}
Yet the body is logged as empty in the console.
I have tried sending a request using curl with no success. I also tried creating an HTML template form and submitting it with no luck.
Any sort of help or explanation is highly appreciated.
You have a trailing slash in your route definition, but in your Postman request its missing. If you use a library, you can typically handle this case.