Skip to content

[API Proposal]: Add QUERY verb support to HttpClient #113522

@MitchBodmer

Description

@MitchBodmer

Background and motivation

With the new QUERY verb reaching the Proposed Standard maturity level, now might be the right time to add it to HttpClient.

API Proposal

These methods added to HttpClient:

namespace System.Net.Http
{
    public partial class HttpClient : HttpMessageInvoker
    {
        public Task<HttpResponseMessage> QueryAsync(string? requestUri, HttpContent? content);

        public Task<HttpResponseMessage> QueryAsync(Uri? requestUri, HttpContent? content);

        public Task<HttpResponseMessage> QueryAsync(string? requestUri, HttpContent? content, CancellationToken cancellationToken);

        public Task<HttpResponseMessage> QueryAsync(Uri? requestUri, HttpContent? content, CancellationToken cancellationToken)
    }
}

A new static HttpMethod member called Query:

public partial class HttpMethod
{
    public static HttpMethod Query { get; }
}

And finally, all the expected QueryAsJsonAsync overloads:

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

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

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

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

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

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

API Usage

This is intended to be used in the same way the current verbs with a body are used.

HttpClient httpClient = new();

var response = await httpClient.QueryAsync("https://myuri.com/path", someHttpContent);

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions