Backend and APIs · Pattern

Middleware

Code that runs on every request before or after the main handler, for jobs such as logging, checking sign-in, adding headers and handling errors.

Jobs and glue · updated

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.

More in Backend and APIs

Jobs and glue

All 26 Backend and APIs terms

Crafted in the dark. Shipped to the world.

Tell us what you are building. You get a private project space with a proposal and a line-by-line quote within a day.