Say, I have the following minimal API:
var builder = WebApplication.CreateBuilder(args);
// Routing options
builder.Services
.Configure<RouteOptions>(options =>
{
options.LowercaseUrls = true;
options.LowercaseQueryStrings = true;
});
await using var app = builder.Build();
// API
app.MapGet("/api/customers/{id:int}", async (VRContext db, int id) =>
await db.Customers.FindAsync(id) switch
{
{ } customer => Results.Ok(customer),
null => Results.NotFound(new { Requested_Id = id, Message = $"Customer not found." })
});
//app.MapControllers();
await app.RunAsync();
When I pass non-existing id
, I get the following JSON:
{
"requested_Id": 15,
"message": "Customer not found."
}
The problem is that letter I
in requested_Id
is not lowercase, although I configured it in Configure<RouteOptions>
. But when I start using fully-fledged controller, then I correctly get requested_id
. How do I achieve the same with MapGet
?