Posts Learn Components Snippets Categories Tags Tools new About
/

How to make an Axios GET request

Learn how to perform an axios GET request from your web application to call an external API with ease

Created on Aug 27, 2021

42 views

What is Axios?


Axios is a promise-based HTTP client for browser applications and the node.js backend. It's a simple and easy-to-use library that many front-end applications depend on to call external API.

How to Install Axios


To get axios into your project you can use npm or yarn package manager.
npm install axios
yarn add axios

How to Perform GET request in Axios


To perform a GET request you can make use of the "get" method and passing in a URL that you want to request. Axios is also a promised-based library that also supports async/await request.
<script>
   import axios from 'axios';

   const response = await axios.get('https://jsonplaceholder.typicode.com/posts/1');

   console.log(response);
</script>
To perform request using the "then" you can write it as follows.
<script>
    import axios from 'axios';

    axios.get('https://jsonplaceholder.typicode.com/posts/1')
        .then(function (response) {
            console.log(response);
        });
</script>
Do note that you can also pass additional "parameters" like below.
<script>
    import axios from 'axios';

    axios.get('https://jsonplaceholder.typicode.com/posts/1', {
            params: { ID: 2 }
        })
        .then(function (response) {
            console.log(response);
        });
</script>
By now you should know How to make an Axios GET request, If you find it helpful do share it with your friends, and happy coding!

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for How to make an Axios GET request

)