dom / latest / response / response.html /

Response()

The Response() constructor creates a new Response object.

Syntax

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 String 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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
Response
40
14
39
No
29
10.1
40
40
39
29
10.3
4.0
accept_readablestream
52
≤79
No
No
39
No
52
52
No
41
10.3
6.0
body_parameter_optional
40
≤79
59
No
29
No
40
40
59
29
No
4.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Response/Response