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
feat: add custom route on route level #5897
base: master
Are you sure you want to change the base?
Conversation
📝 Docs preview for commit fb7ea03 at: https://63c8137d687c8404f5c931d9--fastapi.netlify.app |
fb7ea03
to
814d256
Compare
📝 Docs preview for commit 814d256 at: https://63c8157edcd0ea06de59aa16--fastapi.netlify.app |
This really looks cool 🚀 But if you see it from a different perspective, is that it may lead to routing conflicts if the custom routes overlap with previously defined routes. This can lead to unexpected behavior and make the API more difficult to understand and maintain. Additionally, if the custom routes are not well-designed or validated, they can introduce security vulnerabilities. |
@yezz123 That is the same as define custom route https://fastapi.tiangolo.com/advanced/custom-request-and-route/#create-a-custom-gziprequest-class.
the same as for the custom route class and that is from a different scope. As a user I want to have an ability to overwrite it for endpoint, not for router. |
📝 Docs preview for commit 9142338 at: https://63ce986746614a32b6064712--fastapi.netlify.app |
📝 Docs preview for commit 432faed at: https://63ce9d10cf2f1b37a4c3277f--fastapi.netlify.app |
📝 Docs preview for commit f2f4c85 at: https://63cfec8dcf915303d8af94c7--fastapi.netlify.app |
fixed: #1174 #4437
The problem:
Sometimes it is nice to have the ability to pass a custom route to a specific endpoint. For example, I need to check headers before processing with the body, but FASTAPI forces me to read the body before.
Currently, I can't do it because
route_class_override
uses only internally, and need to reimplement a lot of things to solve it. So, my proposal is to let routers override a route class.I've tried to solve this issue through middlewares but it's not clear to check into middlewares if I should "filter" requests or not based on the path. Another solution is Mount, but it also not solving the problem because it requires creating sub-path for it (the same with
include_router
).PS:
I think my PR partially add support for that one(logically) encode/starlette#1649 encode/starlette#1464