Practice question from Minimal APIs Introduction
What does this code produce when called with /items/abc? A. 200 OK with ItemId=0 B. 200 OK with ItemId=abc C. 404 Not Found D. 400 Bad Request E. 500 Internal Server Error
app.MapGet("/items/{id:int}", (int id) =>
{
return Results.Ok(new { ItemId = id });
});Answer
C
Explanation
The route constraint ':int' requires the id parameter to be an integer. Since 'abc' is not an integer, the route doesn't match and returns 404 Not Found.