HttpResponse represents the response sent from an ASP.NET Core minimal API endpoint to its client. It exposes the response status code, content type, and body, letting an endpoint customize framework defaults when needed. section 5.3.1 section 7.6.1
Minimal APIs inject HttpResponse when it appears as a handler parameter. Use the narrower type when the handler needs response details; use HttpContext when it needs both request and response information. section 7.6.1
Choose the simplest response approach that fits the endpoint:
- Return an object for JSON, a string for text/plain, or an IResult such as Results.NotFound() for a common status code. section 5.6
- Inject HttpResponse when requirements are more specific, then set StatusCode, ContentType, and the body directly. section 5.3.1
Writing a plain-text response
app.MapGet("/teapot", (HttpResponse response) => { response.StatusCode = 418; response.ContentType = MediaTypeNames.Text.Plain; return response.WriteAsync("I'm a teapot!"); }); This endpoint returns status 418 with a plain-text body. Manual construction is useful for specialized responses, but common results are usually shorter with Results or TypedResults. section 5.3.1



