I'm quite new to the concept of a minimal API, but the documentation seems quite clear. You only have to use Results or TypedResults to return the response code you want.
So I made a very basic try:
app.MapPost("/api/test", async context =>
{
var form = await context.Request.ReadFormAsync();
var file = form.Files["File"];
Results.NoContent();
});
But even with that, it always returns a 200 status code. I also checked a lot of other material from .NET 6 and 7 (I target .NET 7) with method delegates that have a return type of Task<IResult> as specified here in the documentation, but I got the same result (200). Note that I also tried returning NotFound, but I still got the same.
app.MapPost("/api/test", TestReturn);
static async Task<IResult> TestReturn(HttpContext context)
{
var form = await context.Request.ReadFormAsync();
var file = form.Files["File"];
return TypedResults.NoContent();
}
Why can't I get anything else than a 200?