I would like to set up sub applications in my FastAPI project. I have my root file which contains the configuration and a "routes" folder where my routes are organized in different files.
main.py
app = FastAPI()
@app.get("/app")
def read_main():
return {"message": "Hello World from main app"}
subapi = FastAPI()
@subapi.get("/sub")
def read_sub():
return {"message": "Hello World from sub API"}
app.mount("/subapi", subapi)
This works, I have access to the FastAPI docs localhot:8000/docs
and localhost:8000/subapi
with my respective routes.
However, when I call a route in my file routes/session.py
from app.main import subapi
@subapi.post(/session)
this route /session
does not appear in the doc and when I test with curl I get a 404
error.
Am I forced to put all my controllers in my main.py
file?
Can someone help me please?