new Response(csv, { headers })A content-disposition header makes the browser save it as a file.
Besides JSX, strings, buffers and JSON, a route can return a standard Response object: status, headers and body are taken from it.
This makes it easy to reuse code written for other web-standard runtimes or to proxy a fetch call straight through. Click a card to see each response.
new Response(csv, { headers })A content-disposition header makes the browser save it as a file.
new Response(null, {
status: 303, headers
})Sends the browser straight back to this page.
fetch(url)Passes a remote response through, cached for five minutes.
With content negotiation, a client tells the server in the Accept header which formats it understands and how much it prefers each one.
The route /response/cities reads the header and returns a Response in the best matching format, or 406 Not Acceptable. It also sends Vary: Accept, so caches keep one copy per format.
Pick an Accept header below. The request is sent with fetch(), as browsers always send their own Accept header when you follow a link.
curl -H "Accept: text/html" https://expo.jeasx.dev/response/cities
curl -H "Accept: application/json" https://expo.jeasx.dev/response/cities
curl -H "Accept: text/csv" https://expo.jeasx.dev/response/cities
curl -H "Accept: text/plain" https://expo.jeasx.dev/response/cities