I want to routes all paths that start with something like “/api” to same handler function.
Such as:
/api/foo
/api/bar
/api/foo/bar
/api/bar/baz/this/that
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 Python Falcon framework.
More info can be found here; It defines the feature as "white-listed “global” functionality."
http://expressjs.com/api.html#app.all
Perhaps you are looking for Falcon's sink facility, e.g.:
class Sink(object):
def on_get(self, req, resp):
resp.body = ('\nTwo things awe me most, the starry sky '
'above me and the moral law within me.\n'
'\n'
' ~ Immanuel Kant\n\n')
app = falcon.API()
handler = Sink().on_get
app.add_sink(handler, prefix='/')
This will route all URLs to the sink handler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With