What HTTP status code should an API return when it cannot produce a response in any format the client's Accept header requests?
Short answer
406 Not Acceptable indicates the server understood the request but cannot produce a response matching any of the media types the client is willing to accept -- ASP.NET Core can be configured to return this automatically when RespectBrowserAcceptHeader-style strict negotiation is…
Advertisement
AModel answer
406 Not Acceptable indicates the server understood the request but cannot produce a response matching any of the media types the client is willing to accept -- ASP.NET Core can be configured to return this automatically when RespectBrowserAcceptHeader-style strict negotiation is enabled and no registered formatter matches, rather than silently falling back to a default format the client didn't actually request.
Example
// Client sends: Accept: application/pdf // No PDF formatter registered for this endpoint // Response: 406 Not Acceptable (if strict negotiation is configured)
Real-world example
An API configured for strict content negotiation correctly returns 406 when a client mistakenly requests an unsupported Accept: application/pdf, giving clear, actionable feedback instead of silently returning JSON the client didn't ask for.
Likely follow-ups
- What's the default behavior if strict negotiation isn't explicitly configured?
- How does a client typically discover which formats are actually supported?
Related topics