I am working on a project where I need to make calls to a REST API. The end points of the API are on three different servers with three different base addresses.
I am using the
System.Net.Http.HttpClient
class to model the HTTP clients.I am planning to have three different HTTP clients, one for each server as the base addresses are different. Let's name them ServerClient1, ServerClient2 and ServerClient 3.
- These three clients would be using the methods in the
HttpClient
class but would have to implement their own methods to process theHttpReponse
from the servers.
For eg:
private async Task<HttpResonseMessage> getPresenceAsync() {
string url="/xxx/yyy/zzzz";
HttpResponseMessage httpResponse=await httpClient.GetAsync(url);
return httpResponse;
}
Which would be a good design decision in this case: Have the ServerClients extend the HttpClient
or have the HttpClient
as a member of the ServerClients?
I was referring to the link below and I personally feel Aggregation would be a better choice as I would not be using all the methods in the HttpClient
Class.
Any different perspective/help is appreciated.
Thanks!