Return web-standard responses

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.

CSV download200
new Response(csv, { headers })

A content-disposition header makes the browser save it as a file.

GET /export.csvtext/csv
Redirect303
new Response(null, {
  status: 303, headers
})

Sends the browser straight back to this page.

GET /redirectLocation: /response
Proxy200
fetch(url)

Passes a remote response through, cached for five minutes.

GET /proxyfrom api.github.com

Content negotiation: one URL, many formats

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.

From the command line

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