How to use ‘Axios’

Sohyun Lee
Oct 23, 2020

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.

--

--