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’sAccept header decides which one.
How It Works
- Client sends
Accept: application/xml, application/json;q=0.9 - Prism parses and ranks the media types by quality factor
- Your available formats are matched against the client’s preferences
- The best match wins
Quick Example
Multi-Format Endpoint
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, usePrismContentNegotiator directly:
Custom Negotiation
Rendering Specific Formats
Skip negotiation and render data in a known format:Direct Rendering
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.