What is the Prefer header?
The Prefer request header, defined in RFC 7240, lets a client indicate preferences for how a request is processed. Preferences are optional hints: the server may honor or ignore them without changing the outcome’s validity.
API Usage & Best Practices
- Control the response body:
return=minimalasks the server to return little or no body, whilereturn=representationasks for the full resource state. - Request asynchronous processing:
respond-asyncasks the server to process the request asynchronously, often answered with202 Accepted;wait=bounds how long the client will wait. - Confirm what was applied: When the server acts on a preference, it can echo it back in the
Preference-Appliedresponse header. RFC 7240 says this is only needed when the response does not already make it obvious, butreturn=minimalandreturn=representationare exactly the cases where a client cannot always tell, so send it for those.
Examples
POST /v1/orders HTTP/1.1Host: api.example.comPrefer: return=minimal, respond-async, wait=10