Performance: Automatic API documentation (Swagger UI)
This affects the initial page load speed and rendering performance of the API docs interface.
from fastapi import FastAPI app = FastAPI(docs_url=None) # disable default docs # Serve Swagger UI only on demand or use lightweight alternative # Or customize to lazy load Swagger UI assets
from fastapi import FastAPI app = FastAPI(docs_url='/docs') # default Swagger UI enabled # No customization or lazy loading
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Default Swagger UI enabled | Moderate (complex DOM for UI) | Multiple reflows during load | High paint cost due to heavy CSS/JS | [X] Bad |
| Swagger UI disabled or lazy loaded | Minimal DOM initially | Single reflow on demand | Lower paint cost, faster rendering | [OK] Good |
from fastapi import FastAPI
app = FastAPI()
@app.get("/hello")
def say_hello():
return {"message": "Hello, world!"}from fastapi import FastAPI
app = FastAPI()
@app.get("/items")
def read_items():
return [{"item_id": 1}]
# You run the app with: uvicorn main:app --port 8000 --host 0.0.0.0
# But /docs returns 404/docs to /api-docs. Which FastAPI app creation code achieves this?Pass the test and this pattern moves unknown