Content Negotiation
The BookNook phone app wants JSON. A reporting tool wants CSV of the same loans. A French user wants error messages in French. You could build three separate endpoints, but HTTP already has a better way: the client says what it can accept, and the server picks the best match it can produce.
The rule
Content-Type says what I'm sending; Accept says what I'd like back.
Four headers do almost all the work:
Content-Typelabels the body of this message:application/json,text/csv,application/xml.Acceptlists the formats the client can read, optionally ranked withqweights from 0 to 1.Accept-Languagedoes the same for human languages, likefr, en;q=0.5.Accept-Encodinglists compressions the client understands, likegzip, br.
GET /v1/members/7/loans HTTP/1.1
Accept: text/csv, application/json;q=0.8
HTTP/1.1 200 OK
Content-Type: text/csv
Vary: Accept
id,book_id,due
901,42,2026-10-09The client preferred CSV (weight 1, the default) over JSON (0.8). The server can produce CSV, so it sends CSV and labels it with Content-Type. The Vary: Accept header tells caches that this URL has several versions depending on Accept, so they must not hand a CSV response to a JSON client.
When negotiation fails, two status codes name the side that failed:
406 Not Acceptable: the server cannot produce anything on the client'sAcceptlist.415 Unsupported Media Type: the client sent a body in a format the server will not read.