feat: add custom route on route level#5897
Conversation
fb7ea03 to
814d256
Compare
|
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. |
|
This pull request has a merge conflict that needs to be resolved. |
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_overrideuses 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) Kludex/starlette#1649 Kludex/starlette#1464