Skip to content

Accept

Description

The Accept request header is an HTTP header used by clients (such as web browsers or APIs) to specify the media types that they can process. This informs the server about the formats the client prefers in response to a request. The server then selects an appropriate content type based on the provided preferences and includes it in the Content-Type response header.

The Accept header supports multiple MIME types, allowing clients to specify their preferred formats in order of priority using quality values (q parameters). If the server cannot serve any of the specified types, it may return a 406 Not Acceptable response.

Syntax

The Accept header follows this syntax:

Accept: <MIME-type>[;q=<quality>], <MIME-type>[;q=<quality>], ...

Components:

  • <MIME-type>:
    Specifies the media type (e.g., text/html, application/json).
  • q=<quality> (optional):
    A quality factor between 0 and 1, where 1 is the highest priority.
  • Multiple types can be listed, separated by commas.

Examples

Requesting JSON Format

A client requests JSON data from a server:

GET /api/data HTTP/1.1
Host: example.com
Accept: application/json

The server responds with JSON data:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "message": "Hello, world!"
}

Requesting multiple formats with priorities

A client requests HTML, JSON, and XML, preferring HTML over JSON and JSON over XML:

GET /resource HTTP/1.1
Host: example.com
Accept: text/html;q=1.0, application/json;q=0.8, application/xml;q=0.5

The server, preferring HTML, responds with:

HTTP/1.1 200 OK
Content-Type: text/html

<!DOCTYPE html>
<html>
<head><title>Example</title></head>
<body><p>Hello, world!</p></body>
</html>

Requesting any media type

A client indicates that it can accept any media type:

GET /content HTTP/1.1
Host: example.com
Accept: */*

The server can respond with any available format, such as plain text:

HTTP/1.1 200 OK
Content-Type: text/plain

Hello, world!