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

Provide a way to iterate over route handlers #8

Closed
cpsievert opened this issue Jan 12, 2018 · 6 comments
Closed

Provide a way to iterate over route handlers #8

cpsievert opened this issue Jan 12, 2018 · 6 comments

Comments

@cpsievert
Copy link
Contributor

It doesn't seem as though there is a way to iterate over all the handlers of a given route, which could be useful, for example, to add a prefix to every route path

@thomasp85
Copy link
Owner

Are there any other use cases for this that you could think of? For your use case I'd rather add a global mount point for the route...

@cpsievert
Copy link
Contributor Author

cpsievert commented Mar 14, 2018

I'd rather add a global mount point for the route

Do you have an example of doing this anywhere?

Are there any other use cases for this that you could think of?

I'm working on an authentication package, which will modify paths of existing routes to "protect views", like is done with flask here

@thomasp85
Copy link
Owner

The global mount point will get pushed soon - I think it has general applicability besides what we discuss here...

So, optimally you would like a way to map over the paths, and reassign the result?

@cpsievert
Copy link
Contributor Author

So, optimally you would like a way to map over the paths, and reassign the result?

yep

@thomasp85
Copy link
Owner

thomasp85 commented Mar 20, 2018

are you thinking an interface where you provide a function that gets the method, path, and handler and then reassigns it itself, e.g.

route$remap_handlers(function(method, path, handler) {
  route$add_handler(method, paste0('/prefix', path), handler)
})

remap_handlers will then take care of removing all handlers up front so only whatever gets reassigned within the function is kept. In this way you have full flexibility in terms of changing both method, path and even handler function if you so wish

@cpsievert
Copy link
Contributor Author

Yea, that looks good!

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

No branches or pull requests

2 participants