-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
β¨ Add support for custom APIRoute
and APIRouter
#13483
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
base: master
Are you sure you want to change the base?
Conversation
- Introduced `route_class` and `router_class` parameters to allow custom route and router classes. - Updated `FastAPI` initialization to use the provided `router_class` and `route_class`. - Modified webhook initialization to respect the custom router class. - Added test cases to validate: - Custom `route_class` and `router_class` usage. - Route naming consistency. - Presence of `X-Response-Time` header in responses. This enhances FastAPIβs flexibility, allowing users to customize route handling and routing behavior.
π Docs preview for commit 262a799 at: https://9cf8cd82.fastapitiangolo.pages.dev Modified Pages |
π Docs preview for commit ff94d84 at: https://dab335ab.fastapitiangolo.pages.dev Modified Pages |
π Docs preview for commit 95d9257 at: https://b03b4ecf.fastapitiangolo.pages.dev Modified Pages |
@Purushot14: great idea, I will definitely try this out! π If it is not get accepted, you can try an alternative way that uses custom_app() π |
APIRoute
and APIRouter
Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
π Docs preview for commit 4e8479a at: https://dd36898e.fastapitiangolo.pages.dev Modified Pages |
tests/test_tutorial/test_custom_request_and_route/test_tutorial004.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
π Docs preview for commit 1b8d728 at: https://e1a3abf5.fastapitiangolo.pages.dev Modified Pages |
π Docs preview for commit 2bc93e3 at: https://0b1d643b.fastapitiangolo.pages.dev Modified Pages |
π Docs preview for commit a7106ee at: https://8fd77e4d.fastapitiangolo.pages.dev Modified Pages |
π Docs preview for commit 71db950 at: https://e629f0b5.fastapitiangolo.pages.dev Modified Pages |
π Docs preview for commit 063c585 at: https://4214ebb3.fastapitiangolo.pages.dev Modified Pages |
@svlandeg, do you have any updates on this? Can we merge this? |
π feat: Support Custom APIRoute and APIRouter in FastAPI
Summary
This PR introduces support for specifying custom
APIRoute
andAPIRouter
classes in FastAPI. It enhances flexibility by allowing users to override the default route and router behavior for advanced use cases.Changes Introduced
route_class
androuter_class
parameters to theFastAPI
class.router_class
is used when initializing the appβs router and webhooks.self.router
to userouter_class
, passingroute_class
as an argument.X-Response-Time
header in responses.Why This is Needed
Testing & Validation
docs_src.custom_api_router.tutorial001
.Related Issues or Discussions
(If applicable, link related issues or discussions here)