Skip to content

Support the new QUERY HTTP method #61089

Closed
1 of 1 issue completed
Closed

Description

@MitchBodmer

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

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    api-suggestion
    on Mar 22, 2025
  2. MitchBodmer commented on Mar 22, 2025

    @MitchBodmer
    Author
  3. captainsafia commented on Mar 24, 2025

    @captainsafia
    Contributor

    @MitchBodmer Thanks for filing this issue!

    The API proposal looks like a good start. I've marked it as api-ready-for-review so that we can take it through the official process.

  4. added
    area-mvc
    api-ready-for-review
    area-minimal
    and removed
    api-suggestion
    on Mar 24, 2025
  5. MitchBodmer commented on Mar 28, 2025

    @MitchBodmer
    Author

    @captainsafia is this the kind of change that would qualify for the "fast process" mentioned here? Or is that just wishful thinking?

  6. halter73 commented on Apr 21, 2025

    @halter73
    Member

    HttpMethod.Query got approved with dotnet/runtime#114489, and I definitely support adding HttpMethods.Query to ASP.NET Core for consistency.

    I'm not sold on MapQuery though. It's the moral equivalent of HttpClient.QueryAsync which was proposed first by dotnet/runtime#113522 but hasn't been approved yet. We don't have Map* methods for every HTTP method like MapTrace or MapOptions.

  7. doominator42 commented on May 26, 2025

    @doominator42
    Contributor

    Since it was not mentioned in the proposal, I suggest to add HttpMethods.Query to the known methods in HostingMetrics.cs.

    Currently, metrics for QUERY endpoints (or any other custom verbs) shows as _OTHER, which is quite inconvenient.

  8. captainsafia commented on May 28, 2025

    @captainsafia
    Contributor

    @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.

  9. doominator42 commented on May 28, 2025

    @doominator42
    Contributor

    @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.

  10. captainsafia commented on Jul 30, 2025

    @captainsafia
    Contributor

    @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?

  11. 12 remaining items

  12. WeihanLi commented on Aug 15, 2025

    @WeihanLi
    Contributor

    Wondering why we prefer static readonly over const, and when should we prefer const

  13. removed this from the .NET 10 Planning milestone on Aug 22, 2025
  14. captainsafia commented on Aug 25, 2025

    @captainsafia
    Contributor

    Closing this since the core API is complete.

  15. halter73 commented on Mar 26, 2026

    @halter73
    Member

    Wondering why we prefer static readonly over const, and when should we prefer const

    @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.

  16. Frulfump commented on Mar 26, 2026

    @Frulfump

    @halter73 I think you meant to ping someone else

  17. halter73 commented on Mar 26, 2026

    @halter73
    Member

    @Frulfump Just thought you would like to know since you gave a 👍 to #61089 (comment)

  18. Frulfump commented on Mar 26, 2026

    @Frulfump

    @halter73 Ah that makes sense, thank you for that!

  19. sander1095 commented on Jun 17, 2026

    @sander1095
    Contributor

    @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.

  20. martincostello commented on Jun 17, 2026

    @martincostello
    Member

    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

  21. sander1095 commented on Jun 17, 2026

    @sander1095
    Contributor

    @martincostello Could you provide a tiny sample on how to get HTTP query to work on minimal api/controller with http query today?

  22. martincostello commented on Jun 17, 2026

    @martincostello
    Member

    [HttpMethod("QUERY")] attribute on a method should do it, right?

  23. marked QUERY verb support #67778 as a duplicate of this issue on Jul 22, 2026
  24. MitchBodmer commented on Jul 31, 2026

    @MitchBodmer
    Author

    @halter73 should we reopen this so we can add the full set of built-in APIs that the other methods have?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-approvedarea-minimalarea-mvc

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions