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 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 aHeaders
object or object literal ofByteString
key/value pairs (see HTTP headers for a reference).
- The status code for the reponse, e.g.,
Examples
In our Fetch Response example (see [[../../../../../../../mdn.github.io/fetch-examples/fetch-response/index|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 |
FetchThe definition of 'Response()' in that specification. | Living Standard | Initial definition |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Chrome Full support 42 Full support 42 Full support 41 Disabled' From version 41: this feature is behind the |
Edge
Full support 14 |
Firefox Full support 39 Full support 39 Full support 34 Disabled' From version 34: this feature is behind the |
IE
No support No |
Opera Full support 29 Full support 29 Full support 28 Disabled' From version 28: this feature is behind the |
Safari
Full support 10.1 |
WebView Android
Full support 42 |
Chrome Android Full support 42 Full support 42 Full support 41 Disabled' From version 41: this feature is behind the |
Firefox Android
Full support Yes |
Opera Android Full support 29 Full support 29 Full support 28 Disabled' From version 28: this feature is behind the |
Safari iOS
Full support 10.3 |
Samsung Internet Android
Full support 4.0 |
body parameter accepts ReadableByteStream |
Chrome
Full support 52 |
Edge
Full support ≤79 |
Firefox
No support No |
IE
No support No |
Opera
Full support 39 |
Safari
No support No |
WebView Android
Full support 52 |
Chrome Android
Full support 52 |
Firefox Android
No support No |
Opera Android
Full support 41 |
Safari iOS
Full support 10.3 |
Samsung Internet Android
Full support 6.0 |
body parameter can be |
Chrome
Full support Yes |
Edge
Full support ≤79 |
Firefox
Full support 59 |
IE
No support No |
Opera
Full support Yes |
Safari
No support No |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support Yes |
Opera Android
Full support Yes |
Safari iOS
No support No |
Samsung Internet Android
Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.'
- Experimental. Expect behavior to change in the future.
- User must explicitly enable this feature.'
- User must explicitly enable this feature.
See also
Response() by Mozilla Contributors is licensed under CC-BY-SA 2.5.