Repaso
EspaƱol
Backend & APIsIntermediateAPI-11

What is middleware in a web framework?

Options

  1. A database driver that connects the app to the database engine
  2. Code that wraps each request and response, like logging or auth (Correct option)
  3. A frontend library that is used for building user interfaces
  4. A message broker that delivers events between the services

Answer

Code that wraps every request/response, e.g. logging, auth, CORS, timing

Why

Middleware is code that runs before and/or after EVERY request, around your endpoint functions, like layers of an onion.

Typical uses: logging, measuring response time, checking authentication, adding CORS headers, handling errors.

The order matters: e.g. authentication must run before your route logic.

Remember

Middleware = code that runs around every request.

Key terms

Practice this question in Repaso