Writing the Requests Service

Get introduced to JavaScript library Axios and learn to send HTTP requests to REST endpoint using Axios.

Now that we understand the authentication flow from the frontend side, let’s write the requests service we will use for data fetching and performing CRUD actions.

Making requests in JavaScript is relatively easy. The node environment and the browser provide native packages such as fetch to allow you to request a server. However, this project will use the axios package for HTTP requests.

Axios Installation

Axios is a popular library mainly used to send asynchronous HTTP requests to REST endpoints. Axios is the perfect library for CRUD operations. However, we will also install axios-auth-refresh. This simple library assists with an automatic refresh of tokens via axios interceptors. To install the axios and axios-auth-refresh packages, we follow these steps:

Step 1


In the social-media-app directory, add the axios and axios-auth-refresh packages by running the following command:

Get hands-on with 1200+ tech skills courses.