HTTP reactive negotiation (source code)

= HTTP reactive negotiation
{c}

<HTTP reactive negotiation> is <HTTP content negotiation> in which the client selects a representation after receiving an initial response identifying alternatives. The mechanism can be as simple as links to the available forms. The specification also calls this agent-driven negotiation.<HTTP Semantics>[§12.2, Reactive Negotiation, initial response and alternatives]{ref}

For an invented example, a client requests `/report`. The response presents links to `/report.html` and `/report.json`, describing the available <HTML> and <JSON> forms. A person or client program chooses <JSON> and requests `/report.json`. The server then returns that representation. The first response can already contain useful content alongside its alternatives; reactive selection does not require it to be an otherwise empty menu.

The specification discusses alternatives in responses with status `300` or `406`, but the defining feature is the client's selection after the first response. The example's suffixes are application conventions: an <HTTP representation>'s actual <media type> is described by its response metadata, rather than established by a filename alone.<HTTP Semantics>[§12.2, alternatives, successful content and 300/406 examples]{ref}

An extra request can add delay. In a toy model with an established connection, $80$ milliseconds per complete request/response exchange, negligible processing and transmission time, and no existing copy of the alternatives, fetching the menu and then a chosen representation takes $160$ milliseconds. A correct <HTTP proactive negotiation> choice in one exchange would take $80$ milliseconds under those same assumptions. These numbers illustrate the additional dependency, not a universal measured performance difference.

The tradeoff can be worthwhile when the client knows requirements that the server cannot infer, or when alternatives can be reused effectively. The server exposes the choices instead of guessing the user's preference. The standard does not prescribe a general automatic selection algorithm for the client, so providing alternatives does not itself establish that every client will make or follow a choice.<HTTP Semantics>[§12.2, applicability, latency disadvantages and automatic-selection limitation]{ref}