Skip to content

Instantly share code, notes, and snippets.

@jonathanpeppers
Last active February 4, 2017 05:23
Show Gist options
  • Save jonathanpeppers/70f83214fcdb4db32cbdbb7c8bc95cc7 to your computer and use it in GitHub Desktop.
Save jonathanpeppers/70f83214fcdb4db32cbdbb7c8bc95cc7 to your computer and use it in GitHub Desktop.
How to do HttpClient
//Use this class as a singleton in an IoC container
class MyAppClient
{
readonly HttpClient _httpClient = new HttpClient();
public async Task<string> GetChuck()
{
return await _httpClient.Get("http://chucknorris.com");
}
}
//Although "using" is good in general, don't do this
using (var httpClient = new HttpClient())
{
return await _httpClient.Get("http://chucknorris.com");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment