Response: Response() constructor
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.
Note: This feature is available inWeb Workers.
TheResponse() constructor creates a newResponse object.
In this article
Syntax
new Response()new Response(body)new Response(body, options)Parameters
bodyOptionalAn object defining a body for the response. This can be
null(which isthe default value), or one of:optionsOptionalAn 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:
statusThe status code for the response.The default value is
200.statusTextThe status message associated with the status code, such as
"OK".The default value is"".headersAny headers you want to add to your response, contained within a
Headersobject or object literal ofStringkey/value pairs (seeHTTP headers for a reference).By default this is empty.
Examples
In ourFetch Response example (seeFetch Response live)we create a newResponse object using the constructor, passing it a newBlob as a body, and an init object containing a customstatus andstatusText:
const myBlob = new Blob();const myOptions = { status: 200, statusText: "SuperSmashingGreat!" };const myResponse = new Response(myBlob, myOptions);Specifications
| Specification |
|---|
| Fetch> # ref-for-dom-response①> |