Skip to content

Instantly share code, notes, and snippets.

@Mirch
Last active October 13, 2018 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mirch/1cedb4d9e37ee4bf5ef50915832f16de to your computer and use it in GitHub Desktop.
Save Mirch/1cedb4d9e37ee4bf5ef50915832f16de to your computer and use it in GitHub Desktop.
public class RequestSender
{
private static Dictionary<string, HttpClient> _CLIENTS = new Dictionary<string, HttpClient>();
private HttpClient _client;
public RequestSender(string baseURI)
{
var value = _CLIENTS.GetValueOrDefault(baseURI);
if (value == null)
{
var newClient = new HttpClient();
newClient.BaseAddress = new Uri(baseURI);
_CLIENTS.Add(baseURI, newClient);
_client = newClient;
}
else
{
_client = _CLIENTS.GetValueOrDefault(baseURI);
}
}
public async Task<string> Get(string path)
{
var response = await _client.GetStringAsync(path);
return response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment