-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: HttpClient.PatchAsJsonAsync() #60531
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsBackground and motivationIt's natural to have API Proposalnamespace System.Net.Http.Json
{
public static class HttpClientJsonExtensions
{
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, string? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default);
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, Uri? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default);
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, string? requestUri, TValue value, JsonTypeInfo<TValue> jsonTypeInfo = null, CancellationToken cancellationToken = default);
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, Uri? requestUri, TValue value, JsonTypeInfo<TValue> jsonTypeInfo = null, CancellationToken cancellationToken = default);
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, string? requestUri, TValue value, CancellationToken cancellationToken = default);
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, Uri? requestUri, TValue value, CancellationToken cancellationToken = default);
}
} API Usagevar client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json");
var body = new { Sha = "sha" };
var response = await client.PatchAsJsonAsync("https://api.github.com/repos/octocat/hello-world/git/refs/REF", body);
if (response.IsSuccessfulStatusCode)
{
Console.WriteLine("Patched!");
} Alternative DesignsNo response RisksNo response
|
Tagging subscribers to this area: @dotnet/area-system-text-json Issue DetailsBackground and motivationIt's natural to have API Proposalnamespace System.Net.Http.Json
{
public static class HttpClientJsonExtensions
{
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, string? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default);
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, Uri? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default);
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, string? requestUri, TValue value, JsonTypeInfo<TValue> jsonTypeInfo = null, CancellationToken cancellationToken = default);
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, Uri? requestUri, TValue value, JsonTypeInfo<TValue> jsonTypeInfo = null, CancellationToken cancellationToken = default);
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, string? requestUri, TValue value, CancellationToken cancellationToken = default);
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, Uri? requestUri, TValue value, CancellationToken cancellationToken = default);
}
} API Usagevar client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json");
var body = new { Sha = "sha" };
var response = await client.PatchAsJsonAsync("https://api.github.com/repos/octocat/hello-world/git/refs/REF", body);
if (response.IsSuccessfulStatusCode)
{
Console.WriteLine("Patched!");
} Alternative DesignsNo response RisksNo response
|
@ikesnowy thank you for the API proposal. I've marked it ready for review. |
Looks good as proposed namespace System.Net.Http.Json
{
public static partial class HttpClientJsonExtensions
{
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, string? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default);
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, Uri? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default);
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, string? requestUri, TValue value, JsonTypeInfo<TValue> jsonTypeInfo, CancellationToken cancellationToken = default);
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, Uri? requestUri, TValue value, JsonTypeInfo<TValue> jsonTypeInfo, CancellationToken cancellationToken = default);
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, string? requestUri, TValue value, CancellationToken cancellationToken);
public Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, Uri? requestUri, TValue value, CancellationToken cancellationToken);
}
} |
@bartonjs @eiriktsarpalis the defaults in the proposed API create an ambiguity when calling as Removing up-for-grabs, please add back when resolved. |
Sorry, I updated the proposal, should be ok now |
Background and motivation
#45405
It's natural to have
PatchAsJsonAsync
when we already gotPostAsJsonAsync
andPutAsJsonAsync
.API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: