I have an application with the following layers:
- Web API - Provides an access point for external calls to enter the application.
- Infrastructure - Provides repositories which allows access to the database.
- Service layer - Responsible for different use cases (e.g. 'Add item to cart').
- Domain - Contains domain objects with business logic.
You can see how they reference each other, in the drawing below.
I want to add a typed http client, to fetch certain information from an external API.
In what layer/project, should the typed client be created?
My reasoning so far:
The first thing that came to me, was the infrastructure project. But since the infrastructure points towards the service layer (which needs the data from the API), that means introducing an interface on top of the API. This also means that the response object, from the typed client, must be defined in the infrastructure layer (this is where it starts to get messy).
If that is the case, that means that one of the two following must be true:
A) The service layer gets to depend on the API response directly or
B) The typed client must map the response to an object defined in the service layer.
This means that I can either introduce a dependency, in which case I might as well put it all in the service layer. Or I make the typed client more than a typed client, which really feels like a code smell.