What is API Middleware?
Is a component that participates in the processing of an HTTP Request and the consequent generation of a Response. It acts as a mediator between the client or consumer and the software application service. There are multiple types of middlewares depending on which app they connect to. We will focus on API Middleware.
A middleware
- can access your HTTP request and its related information like headers, method, body, parameters, etc
- sends (or not) the request to the backend application for further processing through the request handler
- return a valid HTTP response to the client or consumer.
- performs actions before or/and after execution of the request handler, since is part of the processing pipeline, allowing flexible compute capabilities.
API Middleware use cases
- Request/response manipulation (e.g. add headers, modify the body, etc)
- Session
- Cross-Origin Resource Sharing (CORS)
- Firewall
- Authentication
- Authorization
- Validation
- Sanitize
- Caching
- Logging and monitoring
- Error handling and exception management
- Content negotiation (e.g. handling different formats for the same resource)
- Rate limiting and Throttling
- Honeypot
- Security (e.g. CSRF protection, Same-Site Cookie)
- Internationalization and localization
- API Versioning
Top comments (0)