Why /post/{id} does not receive a request

I Have a small http server

  http.HandleFunc("/", router.Root)
http.HandleFunc("/post", router.Post)
http.HandleFunc("/post/{id}", router.PostRet)
http.ListenAndServe(":8080", nil)

why when I send a request to localhost:8080/post/2 the answer is from “/” root handler??? and when I write “/post/{id}” should the request url be something like “localhost:8080/post/?id=222” ?

1 Like

What server/muxer are you using? I can not find that syntax in the defaults documentation.

1 Like

I am using net/http

1 Like

And that doesn’t support that syntax, you are adding a handler for /post/{id} literally. Try exactly that URL in your browser…

1 Like

So you suggest using external libraries like gorilla mux ?

1 Like

Either that, or using regular query parameters. Or implementing a muxer on your own that can handle that.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.