Where Is the Data in JavaScript Fetch API?

You called Fetch API like this:

let response = await fetch("https://jsonplaceholder.typicode.com/posts");

It returns a promise that contains a Response object. The Response object contains status, headers, URL, etc. But you can’t find the data anywhere.

So, where is the data?

To get the response body (data), we need to use an additional method call. Response provides multiple promise-based methods to access the body in various formats like:

  • response.text() – reads the response and returns it as text.

  • response.json() – parses the response as JSON.

  • response.blob() – returns the response as a Blob (binary data with type).

Here’s what a fetch() request looks like if you expect the server’s response to your request to be JSON-formatted:

let response = await fetch("https://jsonplaceholder.typicode.com/posts");

let data = await response.json(); // read response body as JSON

console.log(data);

Get my free, weekly JavaScript tutorials

Want to improve your JavaScript fluency?

Every week, I send a new full-length JavaScript article to thousands of developers. Learn about asynchronous programming, closures, and best practices — as well as general tips for software engineers.

Join today, and level up your JavaScript every Sunday!

Thank you, Taha, for your amazing newsletter. I’m really benefiting from the valuable insights and tips you share.

- Remi Egwuda