Responsibilities of a Web Adapter
What does a web adapter actually do? Let's say we want to provide a REST API for our BuckPal application. Where do the responsibilities of the web adapter start and where do they end?
A web adapter usually does these things:
- Maps HTTP requests to Java objects
- Performs authorization checks
- Validates input
- Maps input to the input model of the use case
- Calls the use case
- Maps the output of the use case back to HTTP
- Returns an HTTP response
First of all, a web adapter must listen to HTTP requests that match certain criteria, such as a certain URL path, HTTP method, or content type. The parameters and the content of a matching HTTP request must then be deserialized into objects we can work with.
Commonly, a web adapter then does an authentication and authorization check and returns an error if it fails.
The state of the incoming objects can then be validated. But haven't we already discussed input validation as a responsibility...