julienschmidt / httprouter

A high performance HTTP request router that scales well
https://pkg.go.dev/github.com/julienschmidt/httprouter
BSD 3-Clause "New" or "Revised" License
16.64k stars 1.47k forks source link

End of parameter name with a dot #78

Closed manucorporat closed 8 years ago

manucorporat commented 9 years ago
router.Get("/account/:id.json", handler)
params.ByName("id")

Right now the parameter names end with a slash or the end of the path, how about if the dot also means the end of the parameter?

julienschmidt commented 9 years ago

I actually considered this before, but it is a bit complicated. In contrast to slashes, not every dot separates path segments, which makes the matching a lot more difficult.

manucorporat commented 9 years ago

I have a working version of httprouter with this change, but the code is difficult to understand, so I am not sure what I just changed:

https://github.com/gin-gonic/httprouter/commit/2ecb7ac21a43e5f3e7041826e53dc007a102e397

what do you think? what could fail?

manucorporat commented 9 years ago

I know dots do not separate path segments, but nobody is going to use a parameter name with dots, so in my opinion it makes sense to understand a dot as the end of the parameter name.

julienschmidt commented 9 years ago

See my comment on your commit

squirkle commented 9 years ago

Additionally, something like router.Get("/account/:id.:filetype", handler) could be extremely convenient.

chochkov commented 9 years ago

we'd love to have this feature too :+1:

manucorporat commented 9 years ago

@julienschmidt sorry I just saw your comment in my commit. you are right, this is not trivial

manucorporat commented 9 years ago

@squirkle well, I would not overload the router that much. if you want the extension just do this:

extension := filepath.Ext(filename)
thatnerdjosh commented 5 years ago

@manucorporat is it necessary to create an endpoint for each filetype or is it possible to allow a route to accept multiple filetypes?

example: route /report will not match /report.json or /report.csv as it ends searching before it gets to the file extension

I could, however, create multiple routes with all the file extensions desired. Thoughts?