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
JSON200
Response.json(data)

Sets body and content type in one go.

GET /data.jsonapplication/json
Redirect303
new Response(null, {
  status: 303, headers
})

Sends the browser straight back to this page.

GET /redirectLocation: /response
Custom status418
new Response(body, {
  status: 418
})

Any status code works, even the teapot.

GET /teapottext/plain
Proxy200
fetch(url)

Passes a remote response through, cached for five minutes.