Axios Get Then

Posted on  by admin
The easiest way to make a GET request with Axios is theaxios.get() function.

The first parameter to axios.get() is the URL. For example, below is how you make a GET requestto the URL The 2nd parameter to axios.get() is the Axios options.For example, you don't have to serialize the query string ?answer=42 yourself.

Axios will serializeoptions.params and add it to the query string for you.


Than means youcan use them with promise chaining and async/await. Axios fulfills the request promise when the server responds with an HTTP success code, or rejectsthe request promise when the server responds with an HTTP error.If an error occurs, you can handle the error with .then() or .catch().

You do not need to call .then() or .catch() to execute anAxios request. Axios executes the request immediately on its own.So even if you don't call then(), your server will still get therequest. last modified October 18, 2021. Axios tutorial shows how to generage requests in JavaScript using Axios clientlibrary.

Check the JavaScript fetch tutorialfor an alternative way of creating requests in JavaScript.

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 andperform CRUD operations.

It can be used in plain JavaScript or with a librarysuch as Vue or React. In this tutorial we work with Axios in a Node.js application.

First, we install Axios. We use Node.js version 12.20.1.

We initiate a new Node.js application. We install Axios with npm i axios command. There are multiple methods for creating requests in axios.


Not the answer you're looking for? Browse other questions tagged javascriptpromiseaxios or ask your own question.