What is Content Negotiation?

Turkish: Content Negotiation

Content negotiation lets an HTTP client request a preferred representation, such as JSON or HTML, while the server selects the best match.

What is Content Negotiation?

Content negotiation is how a client asks for a specific representation of the same resource. One endpoint may return the same data as JSON, HTML, XML, or in a different language; the client expresses its preference through HTTP headers.

How Does It Work?

The most common header is Accept. A browser may ask for text/html, while a mobile app may ask for application/json. The server compares the requested media types with what it supports and returns the best match. If no representation is available, it may respond with 406 Not Acceptable.

Negotiation is not limited to media type. Accept-Language is used for language, Accept-Encoding for gzip or brotli compression, and Accept-Charset for character sets.

Use in API Design

In REST API design, content negotiation can serve different clients without duplicating URLs. It is not always necessary, though. For many modern JSON-only APIs, a clear Content-Type: application/json contract and consistent error format are easier to operate.

What to Watch

If the response changes based on headers, the cache key must change as well; otherwise a user expecting HTML might receive JSON. Headers such as Vary: Accept should be planned together with CDN and reverse proxy behavior.

Business Use

Content negotiation is useful when web, mobile, and third-party integrations need different representations of the same resource. Too much flexibility can expand documentation and test coverage, so supported formats should match real client needs.