Repository navigation
Labels
api-approvedAPI was approved in API review, it can be implementedarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates
Description
Background and Motivation
With the new QUERY verb reaching the Proposed Standard maturity level, now might be the right time to add support.
Proposed API
HttpQueryAttribute.cs
+ namespace Microsoft.AspNetCore.Mvc;
+
+ public class HttpQueryAttribute : HttpMethodAttribute
+ {
+ /// <summary>
+ /// Creates a new <see cref="HttpQueryAttribute"/>.
+ /// </summary>
+ public HttpQueryAttribute();
+
+ /// <summary>
+ /// Creates a new <see cref="HttpQueryAttribute"/> with the given route template.
+ /// </summary>
+ /// <param name="template">The route template. May not be null.</param>
+ public HttpQueryAttribute([StringSyntax("Route")] string template);
+ }EndpointRouteBuilderExtensions
namespace Microsoft.AspNetCore.Builder;
+ public static class EndpointRouteBuilderExtensions
+ {
+ /// <summary>
+ /// Adds a <see cref="RouteEndpoint"/> to the <see cref="IEndpointRouteBuilder"/> that matches HTTP QUERY requests
+ /// for the specified pattern.
+ /// </summary>
+ /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param>
+ /// <param name="pattern">The route pattern.</param>
+ /// <param name="requestDelegate">The delegate executed when the endpoint is matched.</param>
+ /// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns>
+ public static IEndpointConventionBuilder MapQuery(
+ this IEndpointRouteBuilder endpoints,
+ [StringSyntax("Route")] string pattern,
+ RequestDelegate requestDelegate);
+
+ /// <summary>
+ /// Adds a <see cref="RouteEndpoint"/> to the <see cref="IEndpointRouteBuilder"/> that matches HTTP QUERY requests
+ /// for the specified pattern.
+ /// </summary>
+ /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param>
+ /// <param name="pattern">The route pattern.</param>
+ /// <param name="handler">The delegate executed when the endpoint is matched.</param>
+ /// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the endpoint.</returns>
+ [RequiresUnreferencedCode(MapEndpointUnreferencedCodeWarning)]
+ [RequiresDynamicCode(MapEndpointDynamicCodeWarning)]
+ public static RouteHandlerBuilder MapQuery(
+ this IEndpointRouteBuilder endpoints,
+ [StringSyntax("Route")] string pattern,
+ Delegate handler);
+ }HttpMethods
+ namespace Microsoft.AspNetCore.Http;
+
+ public static class HttpMethods
+ {
+ /// <summary>
+ /// HTTP "QUERY" method.
+ /// </summary>
+ public static readonly string Query = "QUERY";
+
+ /// <summary>
+ /// Returns a value that indicates if the HTTP request method is QUERY.
+ /// </summary>
+ /// <param name="method">The HTTP request method.</param>
+ /// <returns>
+ /// <see langword="true" /> if the method is QUERY; otherwise, <see langword="false" />.
+ /// </returns>
+ public static bool IsQuery(string method)
+ {
+ return Equals(Query, method);
+ }
+
+ public static string GetCanonicalizedValue(string method) => method switch
+ {
+ ...
+ string _ when IsQuery(method) => Query,
+ ...
+ };
+ }Usage Examples
These are all intended to be used in the same way that their existing counterparts for the other HTTP methods are used.
[HttpQuery]
public async Task<ActionResult<TodoItem>> QueryForTodoItem(QueryParameters queryParameters)
{
...
}var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapQuery("/", queryParameters => dataSource.Search(queryParameters));
app.Run();Alternative Designs
Risks
Reacted by Frulfump, campersau, xp5191, Alireza Tarazani and Benjamin Schober
Sub-issues
Collapse Sub-issuesSub-issues
Loading 1 sub-issues
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates
Activity
MitchBodmer commentedon Mar 22, 2025
Related to dotnet/runtime#113522.
captainsafia commentedon Mar 24, 2025
@MitchBodmer Thanks for filing this issue!
The API proposal looks like a good start. I've marked it as
api-ready-for-reviewso that we can take it through the official process.MitchBodmer commentedon Mar 28, 2025
@captainsafia is this the kind of change that would qualify for the "fast process" mentioned here? Or is that just wishful thinking?
halter73 commentedon Apr 21, 2025
HttpMethod.Querygot approved with dotnet/runtime#114489, and I definitely support addingHttpMethods.Queryto ASP.NET Core for consistency.I'm not sold on
MapQuerythough. It's the moral equivalent ofHttpClient.QueryAsyncwhich was proposed first by dotnet/runtime#113522 but hasn't been approved yet. We don't haveMap*methods for every HTTP method likeMapTraceorMapOptions.doominator42 commentedon May 26, 2025
Since it was not mentioned in the proposal, I suggest to add
HttpMethods.Queryto the known methods in HostingMetrics.cs.Currently, metrics for QUERY endpoints (or any other custom verbs) shows as _OTHER, which is quite inconvenient.
captainsafia commentedon May 28, 2025
@doominator42 Would you like to file an issue or perhaps open a PR for this? Making that change shouldn't require a formal API review since there's no public facing API impact AFAICT.
doominator42 commentedon May 28, 2025
@captainsafia Well, this issue needs to be done first to have
HttpMethods.Query, so can't really open a PR now. Can it be added as implementation detail on this proposal or a note for the implementer? Otherwise I can open a separate issue, I just want to make sure it's not forgotten.captainsafia commentedon Jul 30, 2025
@doominator42 I think the delta of the API proposal is relatively small so it's worth opening an API.
@halter73 Do you have any objection to taking a change just for adding .NET 10?
12 remaining items
WeihanLi commentedon Aug 15, 2025
Wondering why we prefer
static readonlyoverconst, and when should we preferconstcaptainsafia commentedon Aug 25, 2025
Closing this since the core API is complete.
halter73 commentedon Mar 26, 2026
@WeihanLi @Frulfump As I was about to merge #65714, I happened across this issue. The answer is that we changed HeaderNames to use static readonly fields so we could hyper-optimize header string matches based on reference equality. This made some sense for some real inner-loop scenarios where HTTP requests per second can be quite high, so it could be worth it. It was breaking though. It really was unfortunate for people using the HeaderNames class already for attribute parameters. #9514 has the details. People are free to define their own HTTP header and HTTP method constant string for their attributes though.
So basically, I'd rather not go through that again. It's consistent with what we've done before, and even if it's not really faster, it might be sometimes.
Frulfump commentedon Mar 26, 2026
@halter73 I think you meant to ping someone else
halter73 commentedon Mar 26, 2026
@Frulfump Just thought you would like to know since you gave a 👍 to #61089 (comment)
Frulfump commentedon Mar 26, 2026
@halter73 Ah that makes sense, thank you for that!
sander1095 commentedon Jun 17, 2026
@halter73 @martincostello Thoughts on re-opening this and adding support to ASP.NET Core 11?
I see a huge opportunity here, as ASP.NET Core 11 will have OpenAPI 3.2 as default, which has HTTP QUERY support.
Supporting OpenAPI 3.2 and HTTP QUERY in ASP.NET Core will make it one of the first frameworks to have support for this in the whole stack, which would be fantastic!
Not having support dampens the release a bit, as now OpenAPI 3.2 is the default but HTTP QUERY can't be used. If developers would use code generators to generate server code based on an OpenAPI 3.2 document, ASP.NET Core 11 would not be supported as it doesn't have QUERY support.
martincostello commentedon Jun 17, 2026
You can use HTTP QUERY, it's just doesn't have a full set of built-in APIs that other methods have.
The only constraint I'm aware of is making metrics and tracing support it: #63276
sander1095 commentedon Jun 17, 2026
@martincostello Could you provide a tiny sample on how to get HTTP query to work on minimal api/controller with http query today?
martincostello commentedon Jun 17, 2026
[HttpMethod("QUERY")]attribute on a method should do it, right?MitchBodmer commentedon Jul 31, 2026
@halter73 should we reopen this so we can add the full set of built-in APIs that the other methods have?