How to use ‘Axios’

What is Axios?

Axios is an HTTP client library that executes HTTP data requests asynchronously. Ajax can be called quickly using async/await syntax in a Promise-based API format.

The way to install Axios is very simple and easy, just type “ npm install axios “ in npm!

How to Use?

  • GET

Request data by ‘GET’ method with the URL.

On success, the value in ‘.then’ is returned, and on error, the value in ‘.catch’ is returned.

  • POST

Pretty similar to ‘GET’ request. Request data in the ‘POST’ method with the corresponding URL.

On success, the value in ‘.then’ is returned, and on error, the value in ‘.catch’ is returned.

  • ASYNC/AWAIT

-async

‘async/await’ is a method newly added to ES8, and the Async function is used when defining asynchronous functions.

Functions with async always return a promise. If the value is not a promise, it is wrapped in the promise and returned.

-await

Await is used to wait for a promise, and can only be used within async.

If the await keyword is attached, it waits for the promise to be processed, and the result is returned after that.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store