feat: add custom route on route level #5897
Open
+94
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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