Prefer
Influencing how a server processes a request without changing its semantics is achieved through the Prefer request header, which communicates optional processing preferences.
Usage
The Prefer header enables clients to express preferences about how a server processes a request and constructs a response. Preferences are advisory. A server is free to ignore any or all preferences without causing the request to fail. When a server honors one or more preferences, the Preference-Applied response header confirms which ones were applied.
The header follows an extensible token-based syntax. Multiple preferences appear as a comma-separated list, and each preference accepts optional parameters delimited by semicolons.
Prefer: preference-name; parameter=value
The IANA Preferences Registry maintains the list of registered preference tokens. Non-registered preferences are allowed as long as the server understands them. Unrecognized tokens are silently ignored.
The Prefer header is widely used in RESTful APIs, OData services, and PostgREST to control response verbosity, asynchronous processing, and error handling behavior.
Directives
respond-async
The respond-async preference asks the server to process
the operation asynchronously instead of waiting for completion.
A server honoring this preference typically returns 202
Accepted with a Location header pointing to a
status monitoring endpoint.
Prefer: respond-async
return=minimal
The return=minimal preference requests a minimal response body
after a successful operation. For POST or PUT
requests creating or updating a resource, the server omits the
resource representation and returns only status and headers. This
reduces bandwidth when the client does not need the full response.
Prefer: return=minimal
return=representation
The return=representation preference asks the server to
include the full current state of the resource in the response
body after processing. This eliminates the need for a follow-up
GET request to retrieve the updated resource.
Prefer: return=representation
handling=lenient
The handling=lenient preference asks the server to be tolerant
of minor errors, unknown properties, or edge cases during request
processing. The server processes what is valid and ignores
unrecognized elements rather than rejecting the entire request.
Prefer: handling=lenient
handling=strict
The handling=strict preference asks the server to apply strict
validation. The server rejects requests containing unknown or
invalid elements instead of silently ignoring them.
Prefer: handling=strict
wait
The wait preference specifies the maximum number of seconds the
client is willing to wait for a response. A server unable to
complete processing within the window is free to switch to
asynchronous handling and answer with 202 Accepted,
or to disregard the preference entirely.
Prefer: wait=30
Registered extension preferences
The IANA registry also lists preferences defined
outside the core specification. WebDAV adds
depth-noroot, which asks a PROPFIND or REPORT
to leave the request target itself out of a
multi-status response. The safe preference asks
the server for content filtered for a general
audience, the same signal browsers expose as a
"safe search" setting, and a server that honors it
returns the safe token in
Preference-Applied.
Prefer: safe
OData registers a family of prefixed tokens:
odata.maxpagesize caps the items per collection in
a response, odata.track-changes requests a delta
link for later change tracking,
odata.include-annotations selects which
annotations the response carries,
odata.continue-on-error keeps a batch running
after a failed operation, odata.callback names a
callback URL for asynchronous results,
odata.allow-entityreferences permits entity
references in place of full entities, and
omit-values drops null or default values from the
response. Microsoft Graph and Dynamics clients send
these on everyday paging requests.
Prefer: odata.maxpagesize=50
PostgREST preferences
PostgREST honors the standard handling and
return tokens and adds its own. return=headers-only
answers a write with a Location header
and no body. count=exact, count=planned, and
count=estimated choose how the total row count in
Content-Range is computed.
resolution=merge-duplicates and
resolution=ignore-duplicates turn a POST
into an upsert. missing=default inserts column
defaults in place of nulls for absent fields.
tx=rollback runs the request and rolls back the
transaction, useful for dry runs. timezone sets the
database session time zone, and max-affected
combined with handling=strict rejects a write that
touches more rows than expected.
Prefer: count=exact, return=representation
Example
A client creating a resource through a POST request prefers an asynchronous response and is willing to wait up to 10 seconds before the server switches to asynchronous handling.
Prefer: respond-async, wait=10
A client updating a resource requests the full representation in the response body, avoiding a separate GET request to fetch the updated state.
Prefer: return=representation
A client sending a batch operation to an API asks for lenient handling so the server processes valid entries and skips malformed ones rather than rejecting the entire batch.
Prefer: handling=lenient
See also
- RFC 7240: Prefer Header for HTTP
- RFC 8144: Use of the Prefer Header Field in WebDAV
- RFC 8674: The "safe" HTTP Preference
- PostgREST: Prefer Header
- Preference-Applied
- 202
- HTTP headers