W3cubDocs

/DOM

Response.constructor

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 compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 42
42
41
Disabled
Disabled From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
15 39
39
34
Disabled
Disabled From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
No 29
29
28
Disabled
Disabled From version 28: this feature is behind the Experimental Web Platform Features preference.
10.1
body parameter accepts ReadableByteStream 52 ? No No 39 No
body parameter can be null Yes ? 59 No Yes No
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support 42
42
41
Disabled
Disabled From version 41: this feature is behind the Experimental Web Platform Features preference.
42
42
41
Disabled
Disabled From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Yes Yes 29
29
28
Disabled
Disabled From version 28: this feature is behind the Experimental Web Platform Features preference.
10.3 4.0
body parameter accepts ReadableByteStream 52 52 ? No 29 10.3 6.0
body parameter can be null Yes Yes ? Yes Yes No Yes

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Response/Response