Track
FastAPI
Review routes, Pydantic models, dependencies, auth, async handlers, database sessions, and API tests.
- 01
Path operation order
Declare specific routes before dynamic path parameters so FastAPI matches requests as intended.
routingpath parametersorder - 02
Request models and validation
Use Pydantic request models so FastAPI can parse, validate, document, and type the incoming body.
pydanticvalidationrequest body - 03
Response models as contracts
Return response models that expose the public API shape and filter internal fields.
response modelcontractsserialization - 04
Dependencies as boundaries
Use `Depends` to share request parsing, context, and collaborators without hiding setup inside handlers.
dependenciesdependsboundaries - 05
Auth with security dependencies
Use FastAPI security dependencies so auth is declared in the route contract and OpenAPI schema.
securityauthdependencies - 06
Async handler boundaries
Keep async route handlers non-blocking and await asynchronous collaborators directly.
asyncawaitblocking - 07
HTTPException handling
Raise `HTTPException` for expected client-facing failures instead of returning mixed success and error shapes.
errorshttp exceptionstatus codes - 08
Database session lifecycle
Provide database sessions through a dependency so each request gets a clear unit of work.
databasesessiondependencies - 09
Testing with dependency overrides
Override dependencies in tests instead of calling external services or patching internals.
testingdependency overridestestclient - 10
App structure and routers
Organize feature routers and keep app creation focused on wiring rather than route implementation.
routersstructureapp factory