Content Negotiation

콘텐츠 협상

The Accept header asks for a representation and the server selects a supported response type.

···
html
<div class="viz"><h3>ONE RESOURCE · TWO FORMS</h3><div class="row"><div class="box code" id="accept">Accept: application/json</div><span class="arrow">→</span><div class="box code" id="representation">{ "id": 42 }</div></div><div class="muted" id="content-type">Content-Type: application/json</div></div>
css
.viz{width:94%;height:88%;max-width:960px;padding:clamp(10px,2vmin,18px);border:1px solid var(--line);border-radius:14px;background:var(--surface);font:600 clamp(12px,1.35vw,16px)/1.35 var(--font-sans,system-ui,sans-serif);display:flex;flex-direction:column;gap:clamp(7px,1.8vmin,13px);overflow:hidden}.viz h3{margin:0;color:var(--accent);font:700 clamp(12px,1.35vw,16px)/1.2 var(--font-sans,system-ui,sans-serif);letter-spacing:.04em}.viz .row{display:flex;align-items:center;justify-content:center;gap:clamp(5px,1.4vmin,12px);flex:1;min-height:0}.viz .box{padding:clamp(5px,1.5vmin,12px);border:1px solid var(--line);border-radius:9px;background:var(--bg);text-align:center}.viz .muted{color:var(--muted)}.viz .accent{color:var(--accent)}.viz .code{font-family:ui-monospace,monospace}.viz .pill{padding:3px 7px;border:1px solid var(--line);border-radius:99px;white-space:nowrap}.viz .active{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 12%,var(--surface))}.viz .arrow{color:var(--accent);font:700 18px ui-monospace,monospace}#accept,#representation{width:41%;overflow-wrap:anywhere}.row{gap:5px}
js
let json=false;function draw(){json=!json;document.getElementById('accept').textContent=json?'Accept: application/json':'Accept: text/plain';document.getElementById('representation').textContent=json?'{ "id": 42 }':'order 42';document.getElementById('content-type').textContent='Content-Type: '+(json?'application/json':'text/plain')}draw();setInterval(draw,1400)

In HTTP content negotiation, a client sends the media types it can handle in Accept. The server chooses a representation and reports its type in Content-Type. If none matches, it may return 406 or choose another response according to its behavior.

The demo alternates JSON and text Accept headers for one resource, changing the response shape. When caching, use Vary for request headers that influence the representation so variants do not mix.

When to use

Use it when one API resource is available in JSON, text, or other representations.

Open as page ↗