HTTP
Content Negotiation
Negotiate representation with Accept headers.
By EZ4Code Team
negotiationaccept
Code
# Client requests JSON in English, gzipped
GET /api/users HTTP/1.1
Host: example.com
Accept: application/json
Accept-Language: en-US
Accept-Encoding: gzip
---
# Server responds accordingly
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Language: en-US
Content-Encoding: gzip
Vary: Accept, Accept-LanguageExplanation
Content negotiation lets the client request a preferred representation through Accept, Accept-Language, and Accept-Encoding headers, each with quality values. The server selects the best match and reports it in Content-Type, Content-Language, and Content-Encoding. The Vary header tells caches to differentiate stored responses by the negotiated request headers.