HTTP Content Negotiation

HTTP content negotiation: Accept, Accept-Language, Accept-Encoding, Accept-Charset headers, content type selection, and server-driven vs agent-driven negotiation.

  • JSON7,624 B
  • YAML5,265 B · −31%
  • TOON4,154 B · −46%

How clients and servers agree on a representation: Accept, Accept-Language, Accept-Encoding and Content-Type headers, the Vary header that records dependence, and common media types from JSON and XML to multipart and form encodings.

Use it when

  • You are serving more than one format, language or compression from one URL.
  • You need the correct media type for a payload.

Watch out for

  • Content negotiation interacts with caching: responses that vary must include a Vary header or caches may serve the wrong variant.
  • Servers may ignore Accept; the response Content-Type states what was actually sent.

The data

Headers

HeaderDirectionDescriptionExampleNotes
AcceptRequestClient specifies preferred media types with quality values (q-factor)Accept: application/json, text/html;q=0.9, */*;q=0.8Server responds with Content-Type or 406 Not Acceptable if no match
Accept-LanguageRequestClient specifies preferred natural languagesAccept-Language: en-US,en;q=0.9,es;q=0.8Server may return localized content or 406; often ignored in APIs
Accept-EncodingRequestClient specifies supported content codings (compression algorithms)Accept-Encoding: gzip, deflate, brServer responds with Content-Encoding; brotli (br) offers best compression for text
Accept-CharsetRequestClient specifies acceptable character setsAccept-Charset: utf-8, iso-8859-1;q=0.5Rarely used today; UTF-8 is de facto standard everywhere
Content-TypeRequest/ResponseMedia type of the request/response bodyContent-Type: application/json; charset=utf-8Required for POST/PUT requests with body; server must respect or return 415
Content-EncodingResponseCompression applied to the response bodyContent-Encoding: gzipMust match what client Accept-Encoding advertised; browser auto-decompresses
VaryResponseIndicates which request headers affect cache key for content negotiationVary: Accept, Accept-LanguageCritical for CDNs to cache multiple variants; missing Vary causes wrong content served

Media types

TypeUseNotes
application/jsonREST APIs, configurationStandard for API responses; use application/problem+json for errors (RFC 7807)
application/xmlSOAP, legacy APIs, RSS/Atom feedsStill common in enterprise; use application/atom+xml for feeds
text/htmlWeb pagesAlways include charset=utf-8
text/plainPlain text responsesUse for non-structured text; browser won't render as HTML
application/octet-streamBinary data, file downloadsDefault when type is unknown; browser triggers download
multipart/form-dataFile uploads in HTML formsRequires boundary parameter; use for file uploads not JSON payloads
application/x-www-form-urlencodedHTML form submissions (default)Key=value&key2=value2 format; use for simple form data, not file uploads
application/graphql+jsonGraphQL API responsesEmerging standard; use instead of application/json for GraphQL endpoints

Fields

The shape of this dataset, read from the data itself: every column, its type and a real value. Agents can use this to plan a query without fetching the whole document.

SectionFieldTypeExample
headersheaderstringAccept
headersdirectionstringRequest
headersdescriptionstringClient specifies preferred media types with qua…
headersexamplestringAccept: application/json, text/html;q=0.9, */*;…
headersnotesstringServer responds with Content-Type or 406 Not Ac…
media_typestypestringapplication/json
media_typesusestringREST APIs, configuration
media_typesnotesstringStandard for API responses; use application/pro…

Fetch the same bytes

The static files contain the same reference rows as the API, with no API rate limit. Live metadata, such as view counts, may differ. Use the API for content negotiation; use the static files for a cacheable snapshot.

curl "https://yjtoon.yunusemrevurgun.com/api/dataset/http-content-negotiation?format=toon"
const res = await fetch(
  "https://yjtoon.yunusemrevurgun.com/static-data/dataset/http-content-negotiation.toon"
);
const toon = await res.text();

Rate limit: 120 requests per minute per IP, no key and no signup. API reference →

Topics

  • http
  • content-negotiation
  • accept
  • accept-language
  • accept-encoding
  • media-types

Search the library

Search by a topic, title, or keyword.

Start with a collection

Browse all 205 datasets