Labeling the bytes
A response body is just bytes until the Content Type header gives it a MIME type like text html or application json. The type tells the browser whether to render, download, or parse the payload. Guessing the type from the bytes is risky and is the cause of many rendering bugs.
Asking for a format
The client can express preferences with the Accept header. It lists media types with optional quality values between zero and one that rank them. A server that supports several formats picks the best match and replies, ideally adding a Vary Accept header so caches store each variant separately.
When negotiation fails
- If the server has no acceptable format it may return status 406 Not Acceptable.
- A mismatched Content Type makes the client parse the body wrongly, often silently.
- The charset parameter, such as utf 8, prevents garbled text.
Negotiation also covers language and encoding through parallel Accept Language and Accept Encoding headers, all resolved the same way.
Key idea
Content Type labels a body with a MIME type while the Accept header lets a client rank formats, and the server chooses the best supported match.