func main() { r := httprouter.New() r.GET("/users/:id", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { userID := ps.ByName("id") w.Write([]byte(fmt.Sprintf("User ID: %s", userID))) }) }
func main() { r := httprouter.New() r.POST("/products/:id/reviews", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { productID := ps.ByName("id") review := r.FormValue("review") w.Write([]byte(fmt.Sprintf("Product ID: %s \nReview: %s", productID, review))) }) }This example sets up a POST route that expects a product ID parameter in the URL and a review parameter in the request body. The function then extracts both parameters using `ps.ByName("id")` and `r.FormValue("review")` respectively and returns them in the response.