Enhance FastAPI's Route Ordering to Prevent Unintended Matching #11578
Unanswered
linkedlist771
asked this question in
Questions
Replies: 2 comments
-
I also thought that FastAPI could show warning if more specific paths declared after less specific one. It could be an optional feature |
Beta Was this translation helpful? Give feedback.
0 replies
-
I think there should be a PR to warn this router configs. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
When defining routes in FastAPI, the order matters. In the code above, a request to
/users/me
will actually be handled by the/users/{user_id}
route because it's defined first, even though/users/me
is a more specific route.Operating System
Linux
Operating System Details
Operating System Details Ubuntu 20.04
FastAPI Version
0.108.0
Pydantic Version
2.5.2
Python Version
Python 3.10.14
Additional Context
This issue isn't causing a bug in my current project, but it's something I've run into before and I believe addressing it could improve FastAPI's usability and robustness.
I'm happy to provide any additional details or context if needed. And I'm excited to contribute back to the FastAPI community by helping others with their questions and issues moving forward.
Thanks for considering this suggestion and for all your amazing work on FastAPI!
Beta Was this translation helpful? Give feedback.
All reactions