The Accept request header tells the server which media types the client can handle, such as application/json or text/html. The server uses it for content negotiation: it picks a representation of the resource that matches, or answers with 406 Not Acceptable (or a default format) when it cannot.
The header is how one URL can serve JSON to an API client and HTML to a browser, and how clients choose between versions or formats of the same resource. It is defined in the HTTP semantics specification, RFC 9110.
A client lists media types, separated by commas, in the Accept header. Each entry can carry a quality value q between 0 and 1 (default 1) that expresses preference.
This request means: JSON is preferred, XML is acceptable but less wanted, anything else is a last resort. The server compares this list with the formats it can produce and returns the best match. The response states what it chose in the Content-Type header.
The Vary: Accept response header matters. It tells caches and CDNs that the response depends on the request's Accept value, so a cached JSON response is not served to a client that asked for HTML.
| Value | Meaning |
|---|---|
application/json | Only JSON is wanted |
text/* | Any text type |
*/* | Any type at all |
application/json;q=0.9 | JSON, with a slightly lowered preference |
text/html;q=0 | HTML is explicitly not acceptable |
More specific ranges override less specific ones. In text/*, text/html;level=1, the second entry applies to text/html;level=1. A missing Accept header means the client accepts any media type.
Browsers send long values such as text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8. Do not hard-code assumptions about the exact string.
Server-driven negotiation, which uses Accept, is the most common kind. Related headers negotiate other dimensions:
| Header | Negotiates |
|---|---|
Accept | Media type (JSON, XML, HTML, images) |
Accept-Language | Natural language of the response |
Accept-Encoding | Compression (gzip, br, zstd) |
Accept-Charset | Character set, largely obsolete since UTF-8 is universal |
Negotiation is used for APIs that return JSON or XML from one endpoint, for images (a server may return AVIF or WebP to clients that list them), and for vendor media types that carry an API version, such as application/vnd.example.v2+json.
With the browser Fetch API:
With curl:
With Java's HttpClient:
Spring MVC reads the Accept header automatically. You can declare what a handler produces with the produces attribute, and Spring picks the handler or message converter that matches.
If the client sends Accept: application/pdf and no handler produces it, Spring responds with 406 Not Acceptable. XML output also needs an XML converter on the classpath, such as Jackson's XML module.
These two are often confused.
Accept | Content-Type | |
|---|---|---|
| Direction | Request | Request or response |
| Purpose | What the client wants back | What the body being sent actually is |
| Example | Accept: application/json | Content-Type: application/json on a POST body |
A POST that sends JSON and wants JSON back should set both.
Accept and always returning one format, which breaks clients that asked for another.Vary: Accept on cached responses.Accept to carry data that belongs in the URL or query string, such as a file extension that must be bookmarkable.200 with an HTML error page to an API client that asked for JSON. Return the error in the requested format.The server may reply 406 Not Acceptable, or it may ignore the header and send a default representation. RFC 9110 allows both.
A missing Accept header means the client accepts any media type, equivalent to */*.
Header names are case-insensitive. Media type names are also compared case-insensitively, though lower case is the convention.
Yes. Separate them with commas and use q values to rank them.
The Accept header lets a client declare the response formats it understands, with optional q weights, and lets the server choose the best representation or return 406. Set it on clients, honour it on servers, add Vary: Accept for caches, and do not confuse it with Content-Type.