Axios
Axios
(https://packt.live/2WtWceQ) is a popular JavaScript library that is a promise-based HTTP client. It has many features, including transforming request and response data and canceling requests. We will use this API with React in order to fetch data from the server.
As Axios
is a third-party library, we need to install it first. Once it's installed, we will be ready to make a request to a server. Let's look at a basic example using POST
:
axios({ Â Â method: 'POST', // it could be any other HTTP methods such as GET or DELETE Â Â url: 'https://yourdomain.com/api/posts/new', Â Â headers: {'Content-Type': 'application/json'}, Â Â data: { Â Â Â Â title: 'this is a title', Â Â Â Â body: 'this is body', Â Â } });
In the preceding code, we are requesting the server to accept the data (title and body) and store it in the server. Axios...