Glossary · Phase 8 · APIs
Middleware
Code that wraps every request to an app, for jobs like logging, timing, authentication and adding headers.
Some jobs in an API are like that. Logging, timing, checking an API key, adding headers and catching crashes apply to every request. Copying them into every handler is the duplication you learned to avoid. Middleware wraps the whole app instead.
Try it now
Each layer wraps the next, like nested function calls.
Learn it properly
A web framework, from the inside · Decorators, middleware and error handling: how Flask and FastAPI work. About 40 minutes.
Never trained an AI?
Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account.