How to use Axios for making API calls?

Srajan Gupta
2 min readMay 2, 2020

--

Axios is a client-side library for making API calls, HTTP requests, and performing CRUD operation at the server-side/databases.

In this tutorial, we are going to learn about how to make GET, POST, PUT, and DELETE requests in a frontend framework, such as ReactJs, AngularJs, VueJs, etc. so that we can create, read, update and delete data in the database. This is a very simple tutorial, and I hope you like it.

POST REQUEST

A simple post request will create a new row in the database table. And that new row will generally carry new data, which is sent along with the request as a dictionary object.

When making a post request we need an API endpoint (generally a URL) and off-course the data object we want to post to the database.

AXIOS POST REQUEST

GET REQUEST

A simple get request will retrieve data from the database.

Now there are two ways of retrieving data from the database. We can either retrieve all of the data from the database starting from the first row to the last row of the database. Or, we can retrieve a particular row from the database using a column value such as a primary key (id) in the database table.

Retrieving all the data from the database

AXIOS GET REQUEST

Retrieving only a single row from the database

AXIOS GET REQUEST

PUT REQUEST

A simple put request will update the data of a particular row in the database table.

To update the data of a few columns in the database, of a particular row, firstly we need to know the ID of the row we want to update. And secondly, we need the new data object, we want to push to the database in that particular row.

In the below code, the newDataObj is being pushed to row, where id = 42.

AXIOS PUT REQUEST

DELETE REQUEST

A simple delete request will delete a row from the database at a particular ID. We only need to pass the ID of the row in the API endpoint as given in the below code.

AXIOS DELETE REQUEST

So with this, we come to an end of the tutorial on making API requests through Axios. I hope you like it and gain something from it.

Thank you so much for giving it a read.

--

--