How it works
A web framework passes each request through a chain of middleware functions. Each one can read or change the request, stop it (for example with a 401 when there is no valid session) or pass it on to the next with a call such as next(). Order matters: the body must be parsed before it is validated, and the user checked before any route that needs one.
Express, Hono, Django, Laravel and ASP.NET all work this way, and Fastify offers the same idea as hooks. Next.js has a similar layer that runs before a page is served, renamed proxy in Next.js 16. The word also has an older, broader meaning: any software that sits between systems, such as a message broker.
Related terms
More in Backend and APIs
Jobs and glue