✅ Endpoints
hi
can anyone explain why 1 code works and scond no?
also there is third way, but how to get HttpContext here?
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/products/{id}", async (context) =>
{
var id = Convert.ToInt32(context.Request.RouteValues["id"]);
await context.Response.WriteAsync($"ID {id}");
});
});app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/products/{id}", async (context) =>
{
var id = Convert.ToInt32(context.Request.RouteValues["id"]);
await context.Response.WriteAsync($"ID {id}");
});
});app.MapGet("/products/{id}", async (context) =>
{
var id = Convert.ToInt32(context.Request.RouteValues["id"]);
await context.Response.WriteAsync($"ID {id}");
});app.MapGet("/products/{id}", async (context) =>
{
var id = Convert.ToInt32(context.Request.RouteValues["id"]);
await context.Response.WriteAsync($"ID {id}");
});also there is third way, but how to get HttpContext here?
app.MapGet("/products/{id}", (string id) => $"Id :{id}");app.MapGet("/products/{id}", (string id) => $"Id :{id}");