content negotiation
The way a client and server agree on the format, language or compression of a response using request headers such as Accept.
In more detail
The caller sends a wish list, the server picks the best representation it can make and labels it with Content-Type, and it adds Vary so caches know the answer depended on a request header. If nothing on the wish list can be produced, the honest answer is 406. The same mechanism covers language and compression with different header names.
Related terms
- Accept header — The request header in which a client lists the formats it can read, such as Accept: application/json.
- Content-Type — The header that states what format a message body is in, such as application/json.
- Vary header — The response header that lists which request headers changed the answer, so caches keep separate copies for each value.
- 406 Not Acceptable — The HTTP status meaning the server cannot produce any format the Accept header asked for.
- HTTP header — A named line of metadata in an HTTP message, such as Content-Type: application/json, that describes the body, the caller or how to handle the exchange.
Taught in
- Headers And Content Negotiation — Modern API Architecture: REST, GraphQL & gRPC
- Versioning APIs — Modern API Architecture: REST, GraphQL & gRPC
- Reading The Request — Modern Java: Virtual Threads & High-Throughput Services