Created
August 13, 2018 15:37
-
-
Save brunossn/66b3dfa53e3f695d3e01a9bcda0b73bb to your computer and use it in GitHub Desktop.
HttpClient extension to send PATCH
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
using Newtonsoft.Json; | |
using System; | |
using System.Net.Http; | |
using System.Text; | |
using System.Threading.Tasks; | |
public static class HttpClientExtensions | |
{ | |
public static async Task<HttpResponseMessage> PatchAsync(this HttpClient client, Uri requestUri, HttpContent content) | |
{ | |
var method = new HttpMethod("PATCH"); | |
var request = new HttpRequestMessage(method, requestUri) | |
{ | |
Content = content | |
}; | |
return await client.SendAsync(request); | |
} | |
public static async Task<HttpResponseMessage> PatchAsJsonAsync<T>(this HttpClient client, Uri requestUri, T value) | |
{ | |
var jsonString = JsonConvert.SerializeObject(value); | |
return await PatchAsync(client, requestUri, new StringContent(jsonString, Encoding.UTF8, "application/json")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment