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

(AkezhanOb1) #1

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” ?

(Norbert Melzer) #2

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

(AkezhanOb1) #3

I am using net/http

(Norbert Melzer) #4

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

(AkezhanOb1) #5

So you suggest using external libraries like gorilla mux ?

(Norbert Melzer) #6

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

(system) closed #7

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