Glossary coding Term Page
Middleware
Call stack layer that intercepts every request for logging, auth, or mutations.
Core Idea
FastAPI middleware follows the ASGI spec: each middleware receives the scope, handles the request, may alter the response, and passes control down the stack. Because it wraps everything, it is the right tool for logging, correlation IDs, CORS headers, or short-circuiting blocked traffic.
Why It Matters Here
Throughout the FastAPI series, middleware is the switchboard for tracing and security policies before routers dispatch to business logic. Coupled with APIRouter prefixes and lifespan hooks, it keeps infrastructure logic centralized while feature routers stay lean.