Skip to content
Workers
Visit Workers on GitHub
Set theme to dark (⇧+D)

Response

Constructor

let response = new Response(body, init)

Parameters

Valid options for the options object include:

  • status int

    • The status code for the response, such as 200.
  • statusText string

    • The status message associated with the status code, like, OK.
  • headers Headers | ByteString

    • Any headers to add to your response that are contained within a Headers object or object literal of ByteString key/value pairs.

Properties

  • body Readable Stream
    • A simple getter to get the body contents.
  • bodyUsed boolean
    • A boolean indicating if the body was used in the response.
  • headers Headers
    • The headers for the request.
  • ok boolean
    • A boolean indicating if the response was successful (status in the range 200-299).
  • redirected boolean
    • A boolean indicating if the response is the result of a redirect. If so, its URL list has more than one entry.
  • status int
    • The status code of the response (for example, 200 to indicate success).
  • statusText string
    • The status message corresponding to the status code (for example, OK for 200).
  • url string
    • The URL of the response. The value is the final URL obtained after any redirects.
  • webSocket
    • This is present in successful WebSocket handshake responses. For example, if a client sends a WebSocket upgrade request to an origin and a worker intercepts the request and then forwards it to the origin and the origin replies with a successful WebSocket upgrade response, the worker sees response.webSocket. This establishes a WebSocket connection proxied through a worker. Note that you cannot intercept data flowing over a WebSocket connection.

Methods

Instance methods

Additional instance methods

Response implements the Body mixin of the Fetch API, and therefore Response instances additionally have the following methods available:


See also