Last active
February 4, 2017 05:23
-
-
Save jonathanpeppers/70f83214fcdb4db32cbdbb7c8bc95cc7 to your computer and use it in GitHub Desktop.
How to do HttpClient
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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