-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Net.Http
Milestone
Description
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
julealgon, kronic, countneuroman, Frulfump and Meir017
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Net.Http