Skip to content

[API Proposal]: HttpClient.PatchAsJsonAsync() #60531

Closed

Description

@ikesnowy

Background and motivation

#45405

It's natural to have PatchAsJsonAsync when we already got PostAsJsonAsync and PutAsJsonAsync.

API Proposal

namespace  System.Net.Http.Json
{
    public static class HttpClientJsonExtensions
    {
        public static Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, string? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default);

        public static Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, Uri? requestUri, TValue value, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default);

        public static Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, string? requestUri, TValue value, CancellationToken cancellationToken);

        public static Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, Uri? requestUri, TValue value, CancellationToken cancellationToken);

        public static Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, string? requestUri, TValue value, JsonTypeInfo<TValue> jsonTypeInfo, CancellationToken cancellationToken = default);

        public static Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient client, Uri? requestUri, TValue value, JsonTypeInfo<TValue> jsonTypeInfo, CancellationToken cancellationToken = default);
    }
}

API Usage

var 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 Designs

No response

Risks

No response

Activity

  1. added
    api-suggestion
    on Oct 18, 2021
  2. ghost added
    untriaged
    on Oct 18, 2021
  3. added this to the 7.0.0 milestone on Oct 18, 2021
  4. added
    api-ready-for-review
    and removed
    untriaged
    on Oct 18, 2021
  5. eiriktsarpalis commented on Oct 18, 2021

    @eiriktsarpalis
    Member

    @ikesnowy thank you for the API proposal. I've marked it ready for review.

  6. bartonjs commented on Oct 19, 2021

    @bartonjs
    Member

    Video

    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);
        }
    }
  7. added
    api-approved
    and removed
    api-ready-for-review
    on Oct 19, 2021
  8. added
    help wanted
    on Oct 19, 2021
  9. removed
    help wanted
    on Oct 19, 2021
  10. scalablecory commented on Oct 19, 2021

    @scalablecory
    Contributor

    @bartonjs @eiriktsarpalis the defaults in the proposed API create an ambiguity when calling as client.PatchAsJsonAsync(uri, value).

    Removing up-for-grabs, please add back when resolved.

  11. ikesnowy commented on Oct 20, 2021

    @ikesnowy
    ContributorAuthor

    @scalablecory

    Sorry, I updated the proposal, should be ok now

  12. ghost added
    in-pr
    on Oct 20, 2021
  13. ghost removed
    in-pr
    on Oct 25, 2021
  14. ghost locked as resolved and limited conversation to collaborators on Nov 24, 2021
  15. added
    User Story
    Cost:S
    on Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Cost:STeam:LibrariesUser Storyapi-approvedapi-suggestionarea-System.Text.Json

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions