Making API Requests in React
In the previous sections, we learned the different ways of requesting data. Also, we discussed the benefits of using Axios
over other methods, such as XMLHttpRequest
and Fetch API.
In this section, based on what we have learned so far, we will make API requests with React. For the exercises, we are going to use NASA Open APIs (https://api.nasa.gov/) to search NASA images. In this chapter, we are only going to focus on how to receive data back from the NASA server using React.
React Boilerplate and Axios
To get started, let's install create-react-app first and then use Axios
to make API requests. Remember that it is not React's job to make API requests to the server. React is for helping us to display content on the screen and it is Axios
, a layer underneath, that makes requests and receives data back from the server.
We will go through an exercise to integrate...