I have an application with the following layers:
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.
Based on the your definitions:
Infrastructure - Provides repositories which allows access to the database.
Service layer - Responsible for different use cases (e.g. 'Add item to cart').
none of these have the responsibility to communicate with 1st and/or 3rd party services. It seems like your Infrastructure layer is a data access layer (in other traditional layered architecture naming), whereas the Service layer is the business logic layer.
After this little detour let's focus on your question where to place the typed client(s). You can reason about that either of the layers can be good home of the typed clients. I would suggest to make a decision based on the followings:
I hope my guidance could be applied for your particular case as well :)