Middleware
Code that sits between a request and the main handler: checks authorization, logs, modifies data. Works along the path to the application and back.
Examples
- Check token before execution;
- Log each request;
- Compress and cache responses.
Why
Common tasks are moved out of the logic into middleware: write once and it works for all requests.