Categories
JavaScript Answers

How to read JSON response with Axios and JavaScript?

Spread the love

Sometimes, we want to read JSON response with Axios and JavaScript.

In this article, we’ll look at how to read JSON response with Axios and JavaScript.

How to read JSON response with Axios and JavaScript?

To read JSON response with Axios and JavaScript, we get the response body from the data property.

For instance, we write

try {
  const res = await axios.get("/end-point");
  console.log(res.data);
} catch (error) {
  // ...
}

to call axios.get to make a get request.

It returns a promise that has the response data.

We get the response body from res.data.

Conclusion

To read JSON response with Axios and JavaScript, we get the response body from the data property.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.