-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routingtriage-focusAdd this label to flag the issue for focus at triageAdd this label to flag the issue for focus at triage
Milestone
Description
Background and Motivation
When using Minimal APIs, using explicit query string or header parameter names using attributes requires a less-minimal amount of attribute declaration that would be possible if the relevant attributes did not only have a default constructor.
Proposed API
namespace Microsoft.AspNetCore.Mvc
{
public static class FromHeaderAttribute
{
+ public FromHeaderAttribute(string name)
}
public static class FromQueryAttribute
{
+ public FromQueryAttribute(string name)
}
public static class FromRouteAttribute
{
+ public FromRouteAttribute(string name)
}
}
Usage Examples
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/search", (
[FromQuery("q")] string? query,
[FromHeader("User-Agent")] string? userAgent) =>
{
return $@"You searched for ""{query}"" using ""{userAgent}"".";
});
app.Run();
Alternative Designs
None, retain the existing usage patterns.
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/search", (
[FromQuery(Name = "q")] string? query,
[FromHeader(Name = "User-Agent")] string? userAgent) =>
{
return $@"You searched for ""{query}"" using ""{userAgent}"".";
});
app.Run();
Risks
None that I'm aware of.
EDIT: Added FromRouteAttribute
too.
iikuzmychov
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-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routingtriage-focusAdd this label to flag the issue for focus at triageAdd this label to flag the issue for focus at triage