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.
Hi :wave:,
Thanks for using Falcon. The large amount of time and effort needed to
maintain the project and develop new features is not sustainable without
the generous financial support of community members like you.
Please consider helping us secure the future of the Falcon framework with a
one-time or recurring donation.
Thank you for your support!
Hi @jhuitema !
We have recently merged some improvements on that front, mainly thanks to @CaselIT .
Could you try installing the latest version from Git master, and check whether the new Inspect Module fits your bill?
Currently the inspect module only saves the string info of most things, but it should not be too hard to also save the actual object alongside them, so that they could be further used for additional analysis.
That's looks like it will solve my problems nicely. I'll have a play and let you kknow how it goes.
Thanks
Hi again @jhuitema !
Have you had a chance to experiment with the new Inspect Module?
As of 3.0.0+, the functionality in question is now a part of our stable releases.
Sorry for the slow response. I've had a play with this and this does exactly what I need (and more).
Thanks so much!
Most helpful comment
That's looks like it will solve my problems nicely. I'll have a play and let you kknow how it goes.
Thanks