-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Mounting sub-applications under APIRouter
#10180
Comments
APIRouter
Here we should either raise on |
I dont see a reason of binding two FastAPI instances, perhaps in your usecase you're trying to merge two applications, in this case you should have a service that extracts endpoints and mounts them into an APIRouter |
@Kludex , have you tried actually running the app and making a request to the endpoint of the subapp? I have recently also struggled with a very similar setup, where I wanted to mount a v1 API and v2 API after a certain prefix, where I figured I should make a router to "hold" the Long story short, I couldn't make it work that way, so I just mounted v1 app to EDIT: Also, I'm far from an expert, but I have a feeling that the TestClient class doesn't really "collaborate" with mounts... That's why I asked if you have tried to actually run the app and reach the endpoints. |
Maybe related #4657 |
the issue is likely related to the way you are defining the routes within the sub-application (subapi). The routing paths within subapi should not include the prefix that you intend to use when mounting it under api_router. |
Even without including the prefix the problem occurs, as I reported on the issue #4656 making the doc link to be wrong |
Any update on this? It's needed. |
https://github.com/tiangolo/fastapi/blob/master/fastapi/routing.py#L812 |
Folllowing. |
Discussed in #8682
Example Code
Description
Is it possible to mount a sub-application under an APIRouter? APIRouter itself has a mount function and accepts similar arguments to mounting a sub-application on a FastAPI instance, but I can't get the routing to actually work (nor can i get the openapi docs or spec to come back from that I would assume are the correct URLs.
The docs for sub applications note that the sub-application will have it's root_path correctly set, and I've tried a few combinations of manually setting the root_path on the subapi instance, but to no avail.
Related
The text was updated successfully, but these errors were encountered: