Add Map and Attribute for QUERY HTTP verb
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
# [API Proposal]: Complete QUERY HTTP method support in ASP.NET Core
## Background and Motivation
[#61089](https://github.com/dotnet/aspnetcore/issues/61089) proposed support for the new `QUERY` verb, now published as [RFC 10008](https://datatracker.ietf.org/doc/html/rfc10008). That issue was closed once the core API was complete, but only a subset was approved. This issue proposes the remaining two APIs, so `QUERY` is supported in the same way as `GET` and `POST`.
Related to [dotnet/runtime#113522](https://github.com/dotnet/runtime/issues/113522), which proposes the corresponding `HttpClient.QueryAsync` APIs.
## Proposed API
### HttpQueryAttribute
```diff
namespace Microsoft.AspNetCore.Mvc;
+ ///
+ /// Identifies an action that supports the HTTP QUERY method.
+ ///
+ public class HttpQueryAttribute : HttpMethodAttribute
+ {
+ ///
+ /// Creates a new .
+ ///
+ public HttpQueryAttribute();
+
+ ///
+ /// Creates a new with the given route template.
+ ///
+ /// The route template. May not be null.
+ public HttpQueryAttribute([StringSyntax("Route")] string template);
+ }
```
### EndpointRouteBuilderExtensions
```diff
namespace Microsoft.AspNetCore.Builder;
public static class EndpointRouteBuilderExtensions
{
+ ///
+ /// Adds a to the that matches HTTP QUERY requests
+ /// for the specified pattern.
+ ///
+ /// The to add the route to.
+ /// The route pattern.
+ /// The delegate executed when the endpoint is matched.
+ /// A that can be used to further customize the endpoint.
+ public static IEndpointConventionBuilder MapQuery(
+ this IEndpointRouteBuilder endpoints,
+ [StringSyntax("Route")] string pattern,
+ RequestDelegate requestDelegate);
+
+ ///
+ /// Adds a to the that matches HTTP QUERY requests
+ /// for the specified pattern.
+ ///
+ /// The to add the route to.
+ /// The route pattern.
+ /// The delegate executed when the endpoint is matched.
+ /// A that can be used to further customize the endpoint.
+ [RequiresUnreferencedCode(MapEndpointUnreferencedCodeWarning)]
+ [RequiresDynamicCode(MapEndpointDynamicCodeWarning)]
+ public static RouteHandlerBuilder MapQuery(
+ this IEndpointRouteBuilder endpoints,
+ [StringSyntax("Route")] string pattern,
+ Delegate handler);
}
```
## Usage Examples
These are all intended to be used in the same way that their existing counterparts for the other HTTP methods are used.
```csharp
[HttpQuery]
public async Task>> QueryForTodoItems(QueryParameters queryParameters)
{
...
}
```
```csharp
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapQuery("/todos", (QueryParameters queryParameters) => dataSource.Search(queryParameters));
app.Run();
```
## Alternative Designs
## Risks
- `HttpClient.QueryAsync` is proposed in [dotnet/runtime#113522](https://github.com/dotnet/runtime/issues/113522), which is still unapproved (though I have it on good authority that no significant push back is anticipated there.).
Contributor guide
Research direction
Locate the existing attribute and endpoint-mapping counterparts for the other HTTP methods, then compare their public API and routing behavior with the proposed HttpQueryAttribute and MapQuery overloads. Done means both APIs are available with the proposed signatures and support QUERY requests in the same way as their existing counterparts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100