Add support for getting the routes and resources set on a falcon.API instance
See original GitHub issueCan we get a publicly exposed way of getting the resources that have routes on a falcon.API object?
Currently I’m only aware of one way to do this, which does not seem clean or safe:
app = falcon.API()
...
routes = copy.copy(app._router._roots)
for route app._router._roots:
routes.extend(route.children)
print(routes)
The use case I want to be able to support is auto-generating the “/info” endpoint based on the currently added routes. The example above is a simplified version of what falcon-apispec has to do to get the URI -> resource mapping that it uses for this use case.
Could we get something like app.get_routes()
or app.get_resources()
? My initial thought is the return value would be a dict with each URI as the key and the connected resource class instance as the value but as long as I can tell which resources are connected to which URI(s) I’ll be happy.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Routing — Falcon 3.1.1 documentation
Falcon routes incoming requests (including WebSocket handshakes) to resources based on a set of URI templates. If the path requested by the client...
Read more >FAQ — Falcon 3.1.1 documentation
I'm setting a response body, but it isn't getting returned. ... However, a single instance of each resource class attached to a route...
Read more >The App Class — Falcon 3.1.1 documentation
Each App instance provides a callable WSGI interface and a routing engine ... Falcon routes incoming requests to resources based on a set...
Read more >Tutorial (WSGI) — Falcon 3.1.1 documentation
First Steps¶. The first thing we'll do is install Falcon inside a fresh virtualenv. To that end, let's create a new project folder...
Read more >Tutorial — Falcon 0.2.0rc1 documentation
In Falcon, you map incoming requests to things called “Resources”. A Resource is just a regular Python class that includes some methods that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That’s looks like it will solve my problems nicely. I’ll have a play and let you kknow how it goes.
Thanks
Sorry for the slow response. I’ve had a play with this and this does exactly what I need (and more).
Thanks so much!