This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.
* Some parts of this feature may have varying levels of support.
Note: This feature is available in Web Workers.
The Response interface of the Fetch API represents the response to a request.
You can create a new Response object using the Response() constructor, but you are more likely to encounter a Response object being returned as the result of another API operation—for example, a service worker FetchEvent.respondWith, or a simple fetch().
Response()Creates a new Response object.
Response.body Read only
A ReadableStream of the body contents.
Response.bodyUsed Read only
Stores a boolean value that declares whether the body has been used in a response yet.
Response.headers Read only
The Headers object associated with the response.
Response.ok Read only
A boolean indicating whether the response was successful (status in the range 200 – 299) or not.
Response.redirected Read only
Indicates whether or not the response is the result of a redirect (that is, its URL list has more than one entry).
Response.status Read only
The status code of the response. (This will be 200 for a success).
Response.statusText Read only
The status message corresponding to the status code. (e.g., OK for 200).
Response.type Read only
The type of the response (e.g., basic, cors).
Response.url Read only
The URL of the response.
Response.error()Returns a new Response object associated with a network error.
Response.redirect()Returns a new response with a different URL.
Response.json()Returns a new Response object for returning the provided JSON encoded data.
Response.arrayBuffer()Returns a promise that resolves with an ArrayBuffer representation of the response body.
Response.blob()Returns a promise that resolves with a Blob representation of the response body.
Response.bytes()Returns a promise that resolves with a Uint8Array representation of the response body.
Response.clone()Creates a clone of a Response object.
Response.formData()Returns a promise that resolves with a FormData representation of the response body.
Response.json()Returns a promise that resolves with the result of parsing the response body text as JSON.
Response.text()Returns a promise that resolves with a text representation of the response body.
In our basic fetch example (run example live) we use a simple fetch() call to grab an image and display it in an <img> element. The fetch() call returns a promise, which resolves to the Response object associated with the resource fetch operation.
You'll notice that since we are requesting an image, we need to run Response.blob to give the response its correct MIME type.
const image = document.querySelector(".my-image");
fetch("flowers.jpg")
.then((response) => response.blob())
.then((blob) => {
const objectURL = URL.createObjectURL(blob);
image.src = objectURL;
});
You can also use the Response() constructor to create your own custom Response object:
const response = new Response();
Here we call a PHP program file that generates a JSON string, displaying the result as a JSON value.
// Function to fetch JSON using PHP
const getJSON = async () => {
// Generate the Response object
const response = await fetch("getJSON.php");
if (response.ok) {
// Get JSON value from the response body
return response.json();
}
throw new Error("*** PHP file not found");
};
// Call the function and output value or error message to console
getJSON()
.then((result) => console.log(result))
.catch((error) => console.error(error));
| Specification |
|---|
| Fetch> # response-class> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
Response |
40 | 14 | 39 | 27 | 10.1 | 40 | 39 | 27 | 10.3 | 4.0 | 40 | 10.3 |
Response |
4240–42Only available in service workers. |
14 | 39 | 2927–29Only available in service workers. |
10.1 | 4240–42Only available in service workers. |
39 | 2927–29Only available in service workers. |
10.3 | 4.0 | 4240–42Only available in service workers. |
10.3 |
arrayBuffer |
42 | 14 | 39 | 29 | 10.1 | 42 | 39 | 29 | 10.3 | 4.0 | 42 | 10.3 |
blob |
42 | 14 | 39 | 29 | 10.1 | 42 | 39 | 29 | 10.3 | 4.0 | 42 | 10.3 |
body |
43 | 14 | 65 | 30 | 10.1 | 43 | 65 | 30 | 10.3 | 4.0 | 43 | 10.3 |
bodyUsed |
42 | 14 | 39 | 29 | 10.1 | 42 | 39 | 29 | 10.3 | 4.0 | 42 | 10.3 |
bytes |
132 | 132 | 128 | 117 | 18 | 132 | 128 | 87 | 18 | No | 132 | 18 |
clone |
40 | 14 | 39 | 27 | 10.1 | 40 | 39 | 27 | 10.3 | 4.0 | 40 | 10.3 |
error_static |
43 | 16 | 39 | 30 | 10.1 | 43 | 39 | 30 | 10.3 | 4.0 | 43 | 10.3 |
formData |
60 | 79 | 39 | 47 | 14.1 | 60 | 39 | 44 | 14.5 | 8.0 | 60 | 14.5 |
headers |
40 | 14 | 39 | 27 | 10.1 | 40 | 39 | 27 | 10.3 | 4.0 | 40 | 10.3 |
json |
42 | 14 | 39 | 29 | 10.1 | 42 | 39 | 29 | 10.3 | 4.0 | 42 | 10.3 |
json_static |
105 | 105 | 115 | 91 | 17 | 105 | 115 | 72 | 17 | 20.0 | 105 | 17 |
ok |
42 | 14 | 39 | 29 | 10.1 | 42 | 39 | 29 | 10.3 | 4.0 | 42 | 10.3 |
redirect_static |
44 | 16 | 39 | 31 | 10.1 | 44 | 39 | 32 | 10.3 | 4.0 | 44 | 10.3 |
redirected |
57 | 16 | 49 | 44 | 10.1 | 57 | 49 | 43 | 10.3 | 8.0 | 60 | 10.3 |
status |
40 | 14 | 39 | 27 | 10.1 | 40 | 39 | 27 | 10.3 | 4.0 | 40 | 10.3 |
statusText |
40 | 14 | 39 | 27 | 10.1 | 40 | 39 | 27 | 10.3 | 4.0 | 40 | 10.3 |
text |
42 | 14 | 39 | 29 | 10.1 | 42 | 39 | 29 | 10.3 | 4.0 | 42 | 10.3 |
type |
40 | 14 | 39 | 27 | 10.1 | 40 | 39 | 27 | 10.3 | 4.0 | 40 | 10.3 |
url |
40 | 14 | 39 | 27 | 10.1 | 40 | 39 | 27 | 10.3 | 4.0 | 40 | 10.3 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Response