Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub router #154

Closed
gsquire opened this issue Aug 16, 2016 · 5 comments
Closed

Sub router #154

gsquire opened this issue Aug 16, 2016 · 5 comments
Milestone

Comments

@gsquire
Copy link

gsquire commented Aug 16, 2016

I searched through the issues but couldn't find anything for sub routers with paths. I don't care about subdomains.

My use case is for API versioning. Here is a snippet from the Gorilla mux:

r := mux.NewRouter()
s := r.PathPrefix("/products").Subrouter()
// "/products/"
s.HandleFunc("/", ProductsHandler)
// "/products/{key}/"
s.HandleFunc("/{key}/", ProductHandler)
// "/products/{key}/details"
s.HandleFunc("/{key}/details", ProductDetailsHandler)

It would be sweet to have a sub router for each version prefix. Is this currently possible or something you could add?

Forgive me if I missed something in the README or documentation.

@rickb777
Copy link

Unlike Gorilla's router, there's no performance gain from using subrouting, because the trie algorithm already handles this inherently.

So the question becomes one of how to construct formulaic paths. Although it would be a nice-to-have feature, my approach to this has been to wrap a *Router within my own path builder code instead.

@gsquire
Copy link
Author

gsquire commented Aug 22, 2016

I'm less interested in performance than being able to unify routes based on a common path. I know how well this library performs already :)

@julienschmidt julienschmidt added this to the v2 milestone Oct 20, 2016
@julienschmidt
Copy link
Owner

See #89
Working on it!

similark pushed a commit to similarweb/httprouter that referenced this issue May 9, 2023
Remove requirement of Service Mesh in Knative

Signed-off-by: Michael Gasch <[email protected]>
@jub0bs
Copy link

jub0bs commented Mar 25, 2024

My two cents: one reason subrouters would be useful is for applying some middleware to only a subrouter.

For instance, I'd like to adapt this net/http v1.22 program to julienschmidt/httprouter, but I currently cannot because there's no way to bind a subrouter to a path without also specifying a method.

@letmestudy
Copy link

letmestudy commented Mar 25, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants