Messages, representations and files
Content negotiation: Accept, q and 406/415
Separate representation, language, compression and preference priority.
Understand the concept
Content negotiation chooses among representations of a resource. Accept concerns media types, Accept-Language language preferences and Accept-Encoding content codings. A q value expresses relative preference; q=0 marks an unacceptable option. A server should know which dimensions it actually supports rather than pretending every requested alternative exists.
Content-Type describes supplied content. An unacceptable response can lead to 406, whereas unsupported request content can lead to 415. A gzip Content-Encoding and JSON Content-Type can coexist: they describe different aspects of the representation.
Vary tells caches which request fields affect response selection. Forgetting language variation can send one visitor’s language to another. Excessive variation reduces cache efficiency. Compare negotiation with explicit language paths, and do not treat browser preference fields as proof of identity or fluency.
When designing multilingual representations and cache behaviour.
Treating Accept as the request body type.
One topic. Three levels of depth.
Accept: application/jsonA JSON response preference.
This page does not send requests to external servers. Messages are readable HTTP/1.1 illustrations, not HTTP/2 or HTTP/3 wire dumps. example.test is reserved for examples. Run commands and JavaScript only in your own test environment; never publish real tokens or cookies.
Try it yourself first.
A client requests JSON but sends XML. Which fields describe what?
Show the solution and explanation
Accept: application/json
Content-Type: application/xmlAccept describes the response preference; Content-Type describes the submitted body.