← Back to Chapters

HTTP 406 – Not Acceptable

? HTTP 406 – Not Acceptable

? Quick Overview

The 406 Not Acceptable HTTP status code indicates that the server cannot generate a response that matches the list of acceptable values defined in the request’s headers, most commonly the Accept header.

? Key Concepts

  • Client specifies acceptable response formats
  • Server supports none of the requested formats
  • Content negotiation failure
  • Often related to Accept, Accept-Language, or Accept-Encoding headers

? Syntax / Theory

HTTP uses content negotiation to decide which representation of a resource should be sent to the client. If the client explicitly requests formats the server cannot provide, the server responds with 406.

? View Code Example
// Client requests only XML, server supports JSON
GET /api/users HTTP/1.1
Host: example.com
Accept: application/xml

? Live Output / Explanation

The server checks the Accept header and finds no compatible response format. As a result, it returns:

? View Code Example
// Server response indicating unacceptable format
HTTP/1.1 406 Not Acceptable
Content-Type: text/plain

Requested format is not supported.

? Interactive Example

Use the simulator below to mimic a client request. The server only supports application/json.

? View Code Example
// JavaScript fetch with restrictive Accept header
fetch("/api/data", {
  headers: {
    Accept: "application/xml"
  }
});

? Use Cases

  • REST APIs enforcing strict response formats
  • Internationalization using Accept-Language
  • Compression handling via Accept-Encoding
  • API versioning through custom media types

✅ Tips & Best Practices

  • Always provide a default response format (like JSON)
  • Avoid overly strict Accept header validation
  • Document supported media types clearly
  • Gracefully fallback instead of failing when possible

? Try It Yourself

  • Send different Accept headers and observe responses
  • Configure a server to return 406 intentionally
  • Implement content negotiation in a sample API
  • Test browser behavior with unsupported MIME types