/text)

    

Returns a promise that resolves with a text representation of the response
body.

##  Examples

###  Fetching an image

In our [ basic fetch example ](https://github.com/mdn/dom-
examples/tree/main/fetch/basic-fetch) ( [ run example live
](https://mdn.github.io/dom-examples/fetch/basic-fetch/) ) we use a simple `
fetch() ` call to grab an image and display it in an [ ` <img> ` ](/en-
US/docs/Web/HTML/Element/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 ` ](/en-US/docs/Web/API/Response/blob) to give the response its
correct MIME type.

js

    
    
    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() ` ](/en-US/docs/Web/API/Response/Response
"Response\(\)") constructor to create your own custom ` Response ` object:

js

    
    
    const response = new Response();
    

###  A PHP Call

Here we call a PHP program file that generates a JSON string, displaying the
result as a JSON value.

js

    
    
    // 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));
    

##  Specifications

Specification  
---  
[ Fetch Standard  
#  response-class  ](https://fetch.spec.whatwg.org/#response-class)  
  
##  Browser compatibility

BCD tables only load in the browser  with JavaScript enabled. Enable
JavaScript to view data.

##  See also

  * [ ServiceWorker API ](/en-US/docs/Web/API/Service_Worker_API)
  * [ HTTP access control (CORS) ](/en-US/docs/Web/HTTP/CORS)
  * [ HTTP ](/en-US/docs/Web/HTTP)

##  Help improve MDN

Was this page helpful to you?

Yes  No

[ Learn how to contribute
](https://github.com/mdn/content/blob/main/CONTRIBUTING.md "This will take you
to our contribution guidelines on GitHub.") .

This page was last modified on  Dec 21, 2023  by  [ MDN contributors ](/en-
US/docs/Web/API/Response/contributors.txt) .

[ View this page on GitHub
](https://github.com/mdn/content/blob/main/files/en-
us/web/api/response/index.md?plain=1 "Folder: en-us/web/api/response \(Opens
in a new tab\)") â¢  [ Report a problem with this content
](https://github.com/mdn/content/issues/new?template=page-report.yml&mdn-
url=https%3A%2F%2Fdeveloper.mozilla.org%2Fen-
US%2Fdocs%2FWeb%2FAPI%2FResponse&metadata=%3C%21--+Do+not+make+changes+below+this+line+--%3E%0A%3Cdetails%3E%0A%3Csummary%3EPage+report+details%3C%2Fsummary%3E%0A%0A*+Folder%3A+%60en-
us%2Fweb%2Fapi%2Fresponse%60%0A*+MDN+URL%3A+https%3A%2F%2Fdeveloper.mozilla.org%2Fen-
US%2Fdocs%2FWeb%2FAPI%2FResponse%0A*+GitHub+URL%3A+https%3A%2F%2Fgithub.com%2Fmdn%2Fcontent%2Fblob%2Fmain%2Ffiles%2Fen-
us%2Fweb%2Fapi%2Fresponse%2Findex.md%0A*+Last+commit%3A+https%3A%2F%2Fgithub.com%2Fmdn%2Fcontent%2Fcommit%2Fdf3ef3c53cb04854ee2dec538b677218b1a10c3c%0A*+Document+last+modified%3A+2023-12-21T05%3A06%3A58.000Z%0A%0A%3C%2Fdetails%3E
"This will take you to GitHub to file a new issue.")

[ MDN logo  ](/)

Your blueprint for a better internet.

  * [ MDN on Mastodon  ](https://mozilla.social/@mdn)
  * [ MDN on X (formerly Twitter)  ](https://twitter.com/mozdevnet)
  * [ MDN on GitHub  ](https://github.com/mdn/)
  * [ MDN Blog RSS Feed  ](/en-US/blog/rss.xml)

##  MDN

  * [ About ](/en-US/about)
  * [ Blog ](/en-US/blog/)
  * [ Careers ](