Content Negotiation

From Delft Solutions
Revision as of 09:12, 14 January 2021 by Thexa4 (talk | contribs) (Created page with "A main feature of the HyperText Transfer Protocol (HTTP) is that it allows clients and servers to negotiate what kind of formats both support. They do this using the Accept...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

A main feature of the HyperText Transfer Protocol (HTTP) is that it allows clients and servers to negotiate what kind of formats both support. They do this using the Accept Header.

This allows implementation of APIs that are Backwards Compatible using Content Negotiation Versioning. Additionally this feature can be used to serve modern image and video formats to clients that indicate support for it.

Mechanism

1. When a client makes a request to a server it supplies all the formats it supports in the Accept Header: `Accept: text/html,application/xhtml+xml`. 2. The server looks at the list the client sent and excludes all formats it does not support. 3. If there are no common formats, the server either responds with 406 Not Acceptable or it picks a fallback format like `text/html`. 4. If there are common formats left, the server picks the one the client marked with the highest priority. 5. The server then returns the content that matches the negotiated format.