What is middleware?
Middleware is a layer that pre-processes requests in web servers. Before a request reaches our controllers, i.e. the functions that implement endpoints/URLs in our API, there's a pre-processing stage. In that stage, the framework parses the request, validates the headers, the content type, the data types, and so on.
Most web development frameworks allow us to create custom middleware, and this is incredibly useful to add custom pre-processing components. For example, we may want to check for custom headers in the request. We can also use middleware to handle authorization and authentication, to log requests, to implement rate-limiting/throttling policies, to track user interactions, and more.
21 авг 2024