Search code examples
pythonfalconframework

Routing all paths to one handler function at Falcon Framework


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


Solution

  • If you're looking for a way to handle all requests before they get routed to appropriate resources, I suggest you to look into middleware components.