EndpointRouteBuilderExtensions
Provides extension methods for IEndpointRouteBuilder that simplify the creation of HTTP endpoints using the minimal APIs approach.
Methods
- MapGet - Maps a
GETrequest to a delegate. - MapPost - Maps a
POSTrequest to a delegate. - MapPut - Maps a
PUTrequest to a delegate. - MapDelete - Maps a
DELETErequest to a delegate. - Map - General purpose mapper for any HTTP method.
MapGet
Creates an endpoint that handles GET requests.
public static IEndpointConventionBuilder MapGet(
this IEndpointRouteBuilder endpoints,
string pattern,
Delegate handler);
MapPost
Creates an endpoint that handles POST requests.
public static IEndpointConventionBuilder MapPost(
this IEndpointRouteBuilder endpoints,
string pattern,
Delegate handler);
MapPut
Creates an endpoint that handles PUT requests.
public static IEndpointConventionBuilder MapPut(
this IEndpointRouteBuilder endpoints,
string pattern,
Delegate handler);
MapDelete
Creates an endpoint that handles DELETE requests.
public static IEndpointConventionBuilder MapDelete(
this IEndpointRouteBuilder endpoints,
string pattern,
Delegate handler);
Map
Creates an endpoint for a specific HTTP method.
public static IEndpointConventionBuilder Map(
this IEndpointRouteBuilder endpoints,
string pattern,
string httpMethod,
Delegate handler);
Sample Usage
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello, World!");
app.MapPost("/items", (Item item) => {
// save item
return Results.Created($"/items/{item.Id}", item);
});
app.Run();
For more details, see the remarks section.