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 HttpClientand use that for every call by passing API URIs inget/post/putmethods.
- create a singleton class for HttpClientHandlerwhich will be shared among allHttpClients and create oneHtppClientfor each domain by setting theBaseAddressproperty. Now we can call the APIs by passing the relative paths inget/post/putmethods.
Which one is the better approach?
Is there any benefit of presetting the BaseAddress? If not, why is this property provided?
 
     
    