Advertisement
Intermediate ASP.NET Core, Content Negotiation & Output Formatters

How does minimal API content negotiation differ from the [ApiController]-based MVC approach, given minimal APIs return results via IResult?

Short answer

Minimal APIs primarily default to JSON via Results.Json() / implicit JSON serialization for returned objects, with less built-in support for automatic multi-format content negotiation compared to MVC's formatter pipeline -- supporting additional formats in minimal APIs typically…

Save ASP.NET Core mock interview
Advertisement
AModel answer
Minimal APIs primarily default to JSON via Results.Json() / implicit JSON serialization for returned objects, with less built-in support for automatic multi-format content negotiation compared to MVC's formatter pipeline -- supporting additional formats in minimal APIs typically requires more explicit, manual logic (checking the Accept header yourself and choosing a response type accordingly) rather than the declarative, pluggable output formatter system MVC controllers benefit from automatically.
app.MapGet("/products/{id}", (int id, HttpContext context) => {
    var product = GetProduct(id);
    if (context.Request.Headers.Accept.ToString().Contains("xml")) {
        return Results.Text(SerializeToXml(product), "application/xml");
    }
    return Results.Json(product);
});
Real-world example
A minimal-API-based service supporting a rare XML-consuming legacy client implements manual Accept header inspection for that one specific endpoint, since minimal APIs lack MVC's automatic formatter-based content negotiation pipeline out of the box.
Likely follow-ups
  • Why did minimal APIs deprioritize built-in multi-format negotiation compared to MVC?
  • How would you build a reusable helper for this manual negotiation pattern across many minimal API endpoints?
Related topics