Accept
Media types the client can understand
What the Accept header does
The Accept header tells the server which media types the client can handle, so the server can pick a matching representation (content negotiation). Accept: application/json asks for JSON; a browser typically sends a list including text/html. Quality values (;q=0.9) express preference.
Example
Accept: application/jsonAccept in practice
Ask for JSON
Accept: application/jsonCommon Accept questions and problems
What do q values mean?
A weight from 0 to 1 that ranks preferences, as in Accept: application/json, text/html;q=0.8. Higher is preferred, and a missing q means 1.
What does */* mean?
Any type is acceptable. Browsers include it as a fallback, and APIs may use it when the client has no preference.
What if the server cannot satisfy Accept?
It may respond 406 Not Acceptable, though many servers return a default representation instead.
Accept vs related headers
- Content-Type: Accept is the client's wish for the response. Content-Type states the actual type of a body.
- Accept-Encoding: Accept-Encoding concerns compression, not media type.
- Accept-Language: Accept-Language concerns the human language of the content.
Where it's used
Accept is a request header. Request headers are sent by the client to describe the request and what the client can accept.