COMPUTER ENGINEER

Jump to examples
Blog
HTTP / HTTPS / TLS6 min study
23/ 70

Messages, representations and files

Content negotiation: Accept, q and 406/415

Separate representation, language, compression and preference priority.

UnderstandStudy an examplePractise

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 TO USE IT

When designing multilingual representations and cache behaviour.

COMMON PITFALL

Treating Accept as the request body type.

01 / PRACTICE

One topic. Three levels of depth.

HTTP / illustrative example
Accept: application/json

A 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.

02 / YOUR TURN

Try it yourself first.

A client requests JSON but sends XML. Which fields describe what?

Show the solution and explanation
Worked solution
Accept: application/json
Content-Type: application/xml

Accept describes the response preference; Content-Type describes the submitted body.