Accept
request headercontent
Lists the response media types the client can handle, in order of preference.
Accept drives content negotiation: the same URL can return HTML to a browser and JSON to an API client. Each type can carry a quality value q from 0 to 1; higher is preferred, and the default is 1.
Syntax
Accept: <type>/<subtype>[;q=<weight>], …
Defined in RFC 9110 §12.5.1 — Accept.
Examples
Accept: application/json
an API client
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
what browsers send for page navigation
Accept: image/avif,image/webp,*/*;q=0.8
browsers asking for images
Good to know
- Most APIs ignore Accept and always return JSON. If yours negotiates, also send
Vary: Accept. - Servers that can't satisfy it may answer 406, but most just send their default type.
How to set Accept
fetch
await fetch("https://api.example.com/", {
headers: { "Accept": "application/json" },
});curl
curl -H 'Accept: application/json' https://api.example.com/
Check it
In the browser, open DevTools → Network, pick a request and look under Request Headers. From the command line, curl's verbose mode prints every header it sends, prefixed with >:
curl -sv https://example.com/ -o /dev/null 2>&1 | grep '^>'
Frequently asked questions
What does */* mean in Accept?
Any media type. Combined with a lower q-value, like */*;q=0.8, it means 'anything else is acceptable, but I prefer the types listed before it'.
Status codes it appears with
Related headers