Last active
March 29, 2017 14:10
-
-
Save jchannon/8103d1127e3e00d8e3be33e467bae147 to your computer and use it in GitHub Desktop.
This file contains 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
public static class HttpClientExtensions | |
{ | |
public static T Get<T>(this HttpClient client, string url) | |
{ | |
var response = client.GetAsync(url).Result; | |
var content = response.Content.ReadAsStringAsync().Result; | |
return JsonConvert.DeserializeObject<T>(content); | |
} | |
public static HttpResponseMessage PostAsJson(this HttpClient client, string url) | |
{ | |
return client.PostAsJson(url, new { }); | |
} | |
public static HttpResponseMessage PostAsJson(this HttpClient client, string url, object model) | |
{ | |
return client.PostAsync(url, new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json")).Result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment