Fastapi: Any idea for paging or separating to different url of the Api docs?

Created on 23 Dec 2020  路  7Comments  路  Source: tiangolo/fastapi

I have tried to add 1k api in a demo, the docs page( 127.0.0.1:8000/docs ) a bit slow, and if there is a multiple members team to do the project, they want see the specific module of api, is it better to separate the api by modules(or APIRouter )?

question

All 7 comments

There won't be any difference even if you separate the docs in a different router as long as it runs in the same process. Does it block your app? It shouldn't because it's running as a coroutine, see

https://github.com/tiangolo/fastapi/blob/5614b94ccc9f72f1de2f63aae63f5fe90b86c8b5/fastapi/applications.py#L157-L168

as @ycd said, it's running as a coroutine and shouldn't block your app.
if you want to separate docs of routes, you can use sub-app instead of APIRouter (I'm not sure it's a good idea)

from fastapi import FastAPI
from uvicorn import run
app = FastAPI()
sub_app = FastAPI()


@app.get("/index")
async def index():
    pass


@sub_app.get("/index")
async def sub_index():
    pass


app.mount(path="/sub", app=sub_app)


if __name__ == '__main__':
    run(app)

/docs

image

/sub/docs

image

I don't think he doesn't want to create a brand new OpenAPI by creating a sub-application.

Since it will not include wanted docs.

If you have 1000 endpoints in a single application, I think that's a bit unrealistic? You should probably be breaking it down into standalone applications at that point. The most I've seen in production is 450 on a mainframe 馃槄

If you have 1000 endpoints in a single application, I think that's a bit unrealistic? You should probably be breaking it down into standalone applications at that point. The most I've seen in production is 450 on a mainframe 馃槄

馃槄馃槄

I agree with breaking endpoints down to standalone applications, maybe by modules, as I can deploy them to different vps to improve the performance.

You can still combine them into a single fastapi instance either way too.

Regardless, if your question is answered, please feel free to close this issue.

Was this page helpful?
0 / 5 - 0 ratings