Response()

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.

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 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 staus 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).

Example

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

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 42
41[1]
39 (39)
34[1]
Not supported

29
28[1]

Not supported
Feature Android Firefox Mobile (Gecko) Firefox OS (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support Not supported Not supported Not supported Not supported Not supported Not supported Not supported

[1] This feature is implemented behind a preference.

See also

Document Tags and Contributors

 Contributors to this page: bryanrsmith, Sebastianz, chrisdavidmills, kscarfone
 Last updated by: bryanrsmith,