Rest api without gorilla - PUT call 404

Take a look over the example below to see how the things works.

var r = mux.NewRouter()

func getEmployee(writer http.ResponseWriter, request *http.Request) {
	// use this to read gorilla mux path variables
	vars := mux.Vars(r)
	id := vars["id"]
	// use this to read from query string
	query := r.URL.Query()
	param1 := query.Get("param1")
	...
}

func main() {
	...
	r.HandleFunc("/employees/{id}", getEmployee).Methods("GET")
	r.HandleFunc("/employees", createEmployee).Methods("POST")
	...
    if err := http.ListenAndServe(":8080", r); err != nil {
         log.Fatalln(err)
    }
}

And some useful resources:

2 Likes