Tips and Tricks

FastAPI

FastAPI Sub Applications


FastAPI tip:

You can use sub-applications when you need two separate OpenAPI schemas and Swagger UIs.

https://fastapi.tiangolo.com/advanced/sub-applications/

You can mount one or many sub-applications.

👇

from fastapi import FastAPI


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)