Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add get_route_paths to path_router #3127

Closed
wants to merge 2 commits into from

Conversation

chris-windsor
Copy link

Added a get_route_paths method to the path_router to return a Vec of the current paths associated with a router.

Motivation

There was a desire to create this feature to support logging frameworks that base their logging off the raw path rather than the path at time of request. I specifically am working on building a client for Apitally in Rust and wanted to support the Axum framework first. I will now be able to supply a list of the applications paths to Apitally. I can see a future where other frameworks desire this functionality as well!

Solution

The paths are already stored in the path_to_route_id of the path_router. The RouteId is not strictly useful in this scenario and is also private. This implementation grabs the keys of path_to_route_id and collects them into a Vec.

@jplatte
Copy link
Member

jplatte commented Dec 28, 2024

I'm sorry but there's been multiple issues asking for this and it has been rejected as a feature.

@jplatte jplatte closed this Dec 28, 2024
@chris-windsor
Copy link
Author

@jplatte aide and utoipa are bloated for developers who don't need that. Developers need access to the inner router somehow. Writing a wrapper is also advocating for bloat. Seems like something that should be considered in the broader community and discussed to find a fair compromise. Could and probably should be behind a feature flag.

@jplatte
Copy link
Member

jplatte commented Dec 28, 2024

You can open a discussion about this elaborating on your use case. Right now I'm fairly strongly against this, but maybe you or others can convince me or the other maintainers.

@Turbo87
Copy link
Collaborator

Turbo87 commented Dec 28, 2024

There was a desire to create this feature to support logging frameworks that base their logging off the raw path rather than the path at time of request.

FWIW you can use https://docs.rs/axum/0.7.9/axum/extract/struct.MatchedPath.html for that without having to touch the router.

@chris-windsor
Copy link
Author

@Turbo87 that is true, and I have implemented that for my use case. However, it would still be nice to retrieve a list of all the routes.

@chris-windsor
Copy link
Author

opened discussion #3139

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants