question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for getting the routes and resources set on a falcon.API instance

See original GitHub issue

Can 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jhuitemacommented, Jun 3, 2020

That’s looks like it will solve my problems nicely. I’ll have a play and let you kknow how it goes.

Thanks

1reaction
jhuitemacommented, Jun 18, 2021

Sorry for the slow response. I’ve had a play with this and this does exactly what I need (and more).

Thanks so much!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found