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, or one of:
init Optional
An options object containing any custom settings that you want to apply to the response. The possible options are:
  • status: The status code for the reponse, 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 Status Comment
Fetch
The definition of 'Response()' in that specification.
Living Standard Initial definition

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support

42

412

15

39

343

No

29

284

10.1
body parameter accepts ReadableByteStream52 ? No No39 No
body parameter can be null Yes ?59 No Yes No
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support

42

411

42

412

Yes Yes

29

284

10.34.0
body parameter accepts ReadableByteStream5252 ? No2910.36.0
body parameter can be null Yes Yes ? Yes Yes No Yes

1. From version 41: this feature is behind the Experimental Web Platform Features preference.

2. From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.

3. From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.

4. From version 28: this feature is behind the Experimental Web Platform Features preference.

See also

Document Tags and Contributors

Last updated by: fscholz,