files/en-us/web/http/reference/headers/prefer/index.md
The HTTP Prefer header allows clients to indicate preferences for specific server behaviors during request processing.
<table class="properties"> <tbody> <tr> <th scope="row">Header type</th> <td> {{Glossary("Request header")}} </td> </tr> <tr> <th scope="row">{{Glossary("Forbidden request header")}}</th> <td>No</td> </tr> </tbody> </table>[!NOTE] Browsers have no handling for the
Preferand {{HTTPHeader("Preference-Applied")}} headers: they are used in custom, implementation-specific clients. Ensure both client and server support this header before relying on it in production.Servers should silently ignore preferences that they do not support, as though the header were not present.
Prefer: <preference>, <preference>, ...
respond-async
return=minimal
return=representation
wait=<seconds>
respond-async preference is also provided, the server should respond asynchronously if processing the request will exceed the wait time.
Otherwise, the server should consider that the client will timeout after the wait time (response behavior depends on server implementation).handling=lenient
handling=strict
Prefer: timezone=America/Los_Angeles.The following request asks for a minimal response.
This is typically a headers-only response (as opposed to return=representation where a representation is included in the response body):
POST /resource HTTP/1.1
Host: example.com
Content-Type: application/json
Prefer: return=minimal
{"id":123, "name": "abc"}
The server responds with a {{httpstatus("201")}}, but does not include any response body.
The {{httpheader("Location")}} header contains a URL with the location of the newly-created resource.
There's no need to include a Preference-Applied header because the absence of a response body is readily apparent:
HTTP/1.1 201 Created
Location: /resource?id=123
This example requests the server start an async processing task:
POST /process HTTP/1.1
Host: example.com
Prefer: respond-async
{
"task": "check-broken-links"
}
The server responds with a {{httpstatus("202", "202 Accepted")}} response indicated the request has been accepted and has not yet completed executing asynchronously.
A Location header points to a status monitor that represents the state of the processing:
HTTP/1.1 202 Accepted
Location: http://example.com/tasks/123/status
The following request includes two preferences; timezone=Jupiter/Red_Spot indicating a time zone preference for the client, and handling=strict for strict validation:
GET /events HTTP/1.1
Host: example.com
Prefer: handling=strict, timezone=Jupiter/Red_Spot
In this implementation, an invalid time zone will throw an error:
HTTP/1.1 400 Bad Request
{{Specifications}}