Axios tutorial shows how to generate requests in JavaScript using Axios client library.
Axios is a promise based HTTP client
for the browser and Node.js. Axios makes it easy to send asynchronous HTTP requests to REST endpoints and perform CRUD operations. It can be used in plain JavaScript or with a library such as Vue or React.
In this tutorial we work with Axios in a Node.js application.
First, we install Axios.
$ node -v
v14.5.0
We use Node.js version 14.5.
$ npm init -y
We initiate a new Node.js application.
$ npm i axios
We install Axios with npm i axios
command.
When we send a request to a server, it returns a response. The Axios response object consists of:
data
- the payload returned from the serverstatus
- the HTTP code returned from the serverstatusText
- the HTTP status message returned by the serverheaders
- headers sent by serverconfig
- the original request configurationrequest
- the request object