Skip to main content

Content Negotiation

Not every client wants JSON. Browsers prefer HTML, spreadsheet tools want CSV, and some integrations need XML. Content negotiation lets a single endpoint serve multiple formats — the client’s Accept header decides which one.

How It Works

  1. Client sends Accept: application/xml, application/json;q=0.9
  2. Prism parses and ranks the media types by quality factor
  3. Your available formats are matched against the client’s preferences
  4. The best match wins

Quick Example

Multi-Format Endpoint
This single endpoint responds with JSON, XML, HTML table, CSV, or plain text — based on what the client asks for.

Supported Formats

Available Formats

Parsing Accept Headers

PrismMediaType.parse handles the full Accept header spec — quality factors, wildcards, and multiple types:
Accept Header Parsing

Manual Negotiation

For custom rendering logic, use PrismContentNegotiator directly:
Custom Negotiation

Rendering Specific Formats

Skip negotiation and render data in a known format:
Direct Rendering
When no Accept header is present, PrismNegotiatedResponse defaults to JSON. When the client sends Accept: */*, the first format in your available list wins — so order your formats by preference.
The built-in HTML renderer creates a simple key-value table. For rich HTML, use content negotiation to detect when HTML is wanted, then render your own template.