Response: Response() constructor
{{APIRef("Fetch API")}}{{AvailableInWorkers}}
The Response() constructor creates a new {{domxref("Response")}}Response object.
Syntax
new Response()
new Response(body)
new Response(body, options)
Parameters
-
body{{optional_inline}}- : An object defining a body for the response. This can be
null(which is the default value), or one of:{{domxref("Blob")}}Blob{{jsxref("ArrayBuffer")}}ArrayBuffer{{jsxref("TypedArray")}}TypedArray{{jsxref("DataView")}}DataView{{domxref("FormData")}}FormData{{domxref("ReadableStream")}}ReadableStream{{domxref("URLSearchParams")}}URLSearchParams{{jsxref("String")}}String- string literal
- : An object defining a body for the response. This can be
-
options{{optional_inline}}- : 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.
The default value is
200.
- : The status code for the response.
The default value is
statusText- : The status message associated with the status code, such as
"OK". The default value is"".
- : The status message associated with the status code, such as
headers- : Any headers you want to add to your response, contained within a
{{domxref("Headers")}}Headers object or object literal of{{jsxref("String")}}String key/value pairs (see HTTP headers for a reference). By default this is empty.
- : Any headers you want to add to your response, contained within a
- : 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:
Examples
In our Fetch Response example (see Fetch Response live)
we create a new Response object using the constructor, passing it a new {{domxref("Blob")}}Blob as a body, and an init object containing a custom status and statusText:
const myBlob = new Blob();
const myOptions = { status: 200, statusText: "SuperSmashingGreat!" };
const myResponse = new Response(myBlob, myOptions);
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}