Creating custom endpoints
The easiest way to create an endpoint is by using the lambda-based endpoints:
app.Map("/map", async context => { await context.Response.WriteAsync("OK"); });
This maps the /map
route to a simple endpoint that writes the word "OK"
to the response stream.
A Note regarding Prior .NET 6.0 Versions
Prior to .NET 6.0, you would map custom endpoints on the endpoints
object inside the lambda that gets passed to the UseEndpoints
method in the Startup.cs
file. With .NET 6.0 and the new minimal API approach, the mapping gets done on the app
object in the Program.cs
file.
You might need to add the Microsoft.AspNetCore.Http
namespace to the using
statements.
You can also map specific HTTP methods (such as GET
, POST
, PUT
, and DELETE
) to an endpoint. The following code shows how to map the GET
and POST
methods:
app.MapGet("/mapget", async context => { await...