What is Content Negotiation
Content negotiation is the process by which a client and server agree on the format of the response. The client specifies what formats it can accept; the server chooses the best match from what it can produce.
How it works
The client sends an Accept header listing preferred formats: Accept: application/json, text/html;q=0.9. The q value (quality factor, 0 to 1) indicates preference — higher means more preferred. The server checks its supported formats, picks the best match, and responds with a Content-Type header confirming the chosen format.
If the server can't produce any of the requested formats, it returns 406 Not Acceptable.
For request bodies (POST, PUT), the client sets Content-Type to tell the server what format the body is in: Content-Type: application/json.
Why it matters
Content negotiation lets a single endpoint serve different formats to different clients. A browser gets HTML, an API client gets JSON, a data pipeline gets CSV — all from the same URL. This is part of Fielding's original REST definition: representations are separated from resources.
See How REST Works for content negotiation in REST API design.