The Prefer request header lets a client ask an API to handle an operation in a particular way. It is useful when different consumers need different amounts of data or different execution modes from the same operation. Prefer is defined by RFC 7240; preferences such as model=summarized are choices defined by the API, not universal meanings of the header. section 13.5.1 section 14.7.4
Choose an account model
GET /accounts with Prefer: model=complete requests complete accounts rather than the usual summaries. A consumer needing less data can request Prefer: model=summarized where that model is offered. The response keeps Content-Type: application/json and uses Preference-Applied to indicate the model returned. Without a model preference, the operation returns its default model. section 13.5.1
Content negotiation is an alternative: a client selects a custom model-specific media type with Accept, and Content-Type identifies the returned type. Prefer keeps the familiar application/json media type. Both approaches can serve read, list, and search operations, but both are uncommon enough to warrant caution: make the available choices and default clear to consumers. section 13.5.1
A preference can change more than the shape of a read response:
- For creation or update, Prefer: model=none or Prefer: return-no-content can omit resource data a consumer does not need. A creation can still return 201 Created with a Location header; model=summarized or model=minimal offers smaller representations. section 13.5.2
- For a long-running simulation, Prefer: response=synchronous requests a response after completion: 201 Created with DONE. With response=asynchronous or no preference, the operation responds immediately with 202 Accepted and IN_PROGRESS. A synchronous option can simplify a limited consumer, but long waits make it less efficient; access can be restricted with a scope. section 14.7.4
Choose a preference when a genuine consumer need justifies another behavior. Specify its values, default, response indication, and any access restrictions; do not make every client wait for a long operation merely because some clients prefer a synchronous response. section 13.5.1 section 14.7.4
