Content negotiation is the mechanism defined in the HTTP specification that allows for the delivery of different versions of a resource at the same URI. This enables the same endpoint to deliver data as HTML to a browser, but as RDF or JSON to an API client.
Request headers
Clients supply preferences via explicit HTTP headers, which the server audits to decide the best response format:
Accept
Defines the media types that the client is willing to receive.
Accept: text/html(Requesting visual website)Accept: application/ld+json(Requesting machine-readable JSON LD)Accept: text/turtle(Requesting standard triples via Turtle)Accept: text/n3(Requesting verbose RDF via Notation3)Accept: application/n-triples(Requesting line-oriented triples via N Triples)Accept: application/trig(Requesting named-graph RDF via TriG)Accept: application/n-quads(Requesting line-oriented quads via N Quads)Accept: text/csv(Requesting tabular data via CSV)
Accept-Language
Informs the server about the client's language preferences (e.g., en-US, fr).
Accept-Encoding
Identifies what compression algorithms (gzip, deflate, br) the client understands.
Importance in the semantic web
In a Semantic Web compliant system, URIs identifying real-world resources should behave intelligently. When a human navigates to the URI, the server employs content negotiation to render the HTML page. When a crawler or reasoning agent requests the exact same URI, the server can provide the machine-readable, structured data, like RDF or JSON.
In this wiki
The Wiki CLI applies content negotiation in two places:
- Page metadata view on Wiki Subcommand build and Wiki Subcommand serve — format chips for JSON-LD, Turtle, N3, RDF/XML, N-Triples, TriG, and N-Quads
- SPARQL endpoint on
wiki servewhen enabled —Acceptselects SPARQL Results JSON, CSV, TSV, or RDF graph serializations (Wiki Subcommand serve)