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
Routing all paths to one handler function #648
Comments
You can always write your own routing function (though it will be slow in comparison). You can get partially there by adding a parameter, but this won't include paths which have extra '/'.
Someone else might know more. |
Unfortunately slash "/" is the delimiter used by the compiled routing code, thus it can not be contained by any URL parameter. @hpincket's example will not work, I guess. |
Right, my example will only work if there are no slashes. On Wed, Nov 4, 2015 at 2:02 PM, Philip Tzou notifications@github.com
|
Falcon has a few features that can help with this. Global logic (such as auth, rate limiting, etc.) can be implemented in Falcon via middleware components or hooks. Sinks can capture all requests with a specific prefix. If none of these fit the bill, I'm sure we can work out a plan to get what you need into the framework. |
I suppose we can introduce some new syntax to URI templates. For example something like |
Another approach (may be more efficient and non-break) is add a new parameter "match_type" to app.add_route('/things/{rest_of_url}', things, match_type=ALL) # match the remaining part include slashes
app.add_route('/things/{just_this}', things, match_type=EXCEPT_SLASH) # match any chars except slash
app.add_route('/things2/{just_this}', things) # match any chars except slash, the default behaviour How do you think @kgriffs? |
The regex approach may prove more flexible (afford more functionality). However, before moving forward I'd like to see some concrete examples of what types of use cases such a feature would serve, that isn't already covered by using a sink. Just to make sure we design this in the right way. |
I ran into this issue and what surprises me is that slashes pose problems in parameters even when URL encoded.
Is this expected behaviour? |
Hi, my use-case is to create microservice for CORS proxy like this EDIT: This was not good idea. Now we are using URL |
same issue here. slash was url encoded |
I use a sink and then extract the rest part with the follow code: parts = req.relative_uri.split('/my_sink_path/')
url = parts[1] But this is ugly! Also I need deal with a # symbol but this part is totally lost in the Request object. |
@Dotrox: There's no way you can capture the text after # symbol. It won't be submitted to the server by any browsers. |
Really need this feature. |
Voting for this feature as well |
Any updates? Really wanted this feature as well |
Any updates to this? |
I am looking for the best way to handle this case. Any updates here? |
Hi everyone, Although probably not exactly what was requested in this issue, if the amount of routes is finite and known in advance, the route suffix feature may be helpful to route all these paths to the same resource with suffixed methods. If we just need to handle all paths to one function as the issue is originally formulated, could a sink work? I was thinking along the lines: import re
import falcon
def one_handler_function(req, resp, path):
resp.media = {
'message': 'Just demonstrating a possible approach to #648',
'path': path,
}
api = falcon.API()
api.add_sink(one_handler_function, re.compile(r'/api(?P<path>/.*)')) That seems to do the job (but probably I'm missing important details):
Sinks are somewhat unwieldy in the sense that one needs to handle FWIW, we have an issue to improve documentation for the sink feature: #1538 . Furthermore, depending on what this one handler function does, simple cases may be handled by responding directly from middleware by signalling the Last but not the least, do not hesitate to share and discuss ideas on our Gitter channels. |
Is it possible to route all paths that start with something like “/api” to same handler function?
Such as:
All should be handled with one function and I should be able to get the full path after /api.
This feature is very handy and I used it often at Node.js Express framework. Now I am looking for ways to accomplish the same thing with Falcon.
More info can be found here; It defines the feature as "white-listed “global” functionality."
http://expressjs.com/api.html#app.all
The text was updated successfully, but these errors were encountered: