Accept
The Accept header specifies which response media types are acceptable to the client.
Writing requests (clients)
Clients use the Content-Type header to indicate the media type responses they are capable of reading, and what they would prefer to receive.
Reading requests (servers)
Keep a mapping of supported media types to available representations; and use a library to match the incoming Accept list with a specific media type. If more than one representation could be selected from, add a Vary header of Vary: Accept
to indicate to caches that the response might vary based on this header.
Overview table
- Name
- Accept
- Description
- Specifies which response media types are acceptable.
- Direction
- Request
- Negotiates
- Content-Type
- List usage in
- Vary
- Specification
- RFC 7231: HTTP/1.1 Semantics and Content §5.3.2. Accept
Syntax
Accept = #( media-range [ accept-params ] ) media-range = ( "*/*" / ( type "/" "*" ) / ( type "/" subtype ) ) *( OWS ";" OWS parameter ) accept-params = weight *( accept-ext ) accept-ext = OWS ";" OWS token [ "=" ( token / quoted-string ) ]
Examples
Prefer HTML or text/x-c, or text/x-dvi if it’s the best the server has after a 20% markdown in quality, or plain text after a 50% markdown in quality:
Accept: text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c
Prefer XHTML or HTML, or generic XML with a reduced preference, or else any content:
Accept: text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8
Implementations
Node.js
- accepts
- negotiator