C#C
C#3y ago
xdd

✅ Endpoints

hi 🙂 can anyone explain why 1 code works and scond no?
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}");
});

also there is third way, but how to get HttpContext here?
app.MapGet("/products/{id}", (string id) => $"Id :{id}");
Was this page helpful?