FastAPI chạy trên ASGI, nên một request đi qua một pipeline bất đồng bộ: ASGI server tiếp nhận, middleware bao quanh, router khớp path, các dependency được giải quyết, hàm path operation của bạn chạy, và giá trị trả về được serialize thành response.
Các giai đoạn
uvicorn (ASGI server)
│ scope + receive/send
▼
ASGI / Starlette middleware ── (CORS, GZip, custom)
▼
Routing ── khớ method + → operation
▼
Dependencies (Depends) ── giả sub-deps, security, yield-setup
▼
operation function ── handler củ ạn chạ
▼
Response model ── validate + serialize sang JSON
▼
tasks ── chạ sau khi response đã ử
▼
Response ──▶ client
