We call several APIs of multiple domains in our project using HttpClient
. I am creating a common HttpClient
to be used for all these API calls. I am confused between two approaches to implement this:
- Create a singleton class for
HttpClient
and use that for every call by passing API URIs inget/post/put
methods. - create a singleton class for
HttpClientHandler
which will be shared among allHttpClient
s and create oneHtppClient
for each domain by setting theBaseAddress
property. Now we can call the APIs by passing the relative paths inget/post/put
methods.
Which one is the better approach?
Is there any benefit of presetting the BaseAddress
? If not, why is this property provided?