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
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:A new static
HttpMethodmember calledQuery:And finally, all the expected
QueryAsJsonAsyncoverloads:API Usage
This is intended to be used in the same way the current verbs with a body are used.
Alternative Designs
No response
Risks
No response