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>
<script> import axios from 'axios'; axios.get('https://jsonplaceholder.typicode.com/posts/1') .then(function (response) { console.log(response); }); </script>
<script> import axios from 'axios'; axios.get('https://jsonplaceholder.typicode.com/posts/1', { params: { ID: 2 } }) .then(function (response) { console.log(response); }); </script>
Leave a reply