Response()

The Response() constructor creates a new Response object.

Syntax

var myResponse = new Response(body, init);

Parameters

body Optional
An object defining a body for the response. This can be null (which is the default value), or one of:
init Optional
An options object containing any custom settings that you want to apply to the response, or an empty object (which is the default value). The possible options are:
  • status: The status code for the response, e.g., 200.
  • statusText: The status message associated with the status code, e.g., OK.
  • headers: Any headers you want to add to your response, contained within a Headers object or object literal of ByteString key/value pairs (see HTTP headers for a reference).

Examples

In our Fetch Response example (see Fetch Response live) we create a new Response object using the constructor, passing it a new Blob as a body, and an init object containing a custom status and statusText:

var myBlob = new Blob();
var init = { "status" : 200 , "statusText" : "SuperSmashingGreat!" };
var myResponse = new Response(myBlob,init);

Specifications

Specification
Fetch Standard (Fetch)
# ref-for-dom-response①

Browser compatibility

BCD tables only load in the browser

See also