Contact Form

Name

Email *

Message *

Cari Blog Ini

Axios Get Request

Learn How to Make GET Requests in Axios

What is Axios?

Axios is a promise-based HTTP Client for nodejs and the browser. It is isomorphic, meaning it can run in the browser and nodejs with the same codebase.

Making GET Requests

You can use GET requests to get data from an endpoint. In Axios, you can make GET requests by passing the relevant config to the axios.get method.

Example

```javascript const axios = require('axios'); axios.get('https://example.com/api/v1/users') .then(res => { console.log(res.data); }) .catch(error => { console.error(error); }); ``` This example will send a GET request to the endpoint https://example.com/api/v1/users. If the request is successful, the then callback will be called with the response data. If the request fails, the catch callback will be called with the error.

Query String Parameters

You can also use Axios to send GET requests with query string parameters. To do this, you can pass an object of query string parameters to the params config option.

Example

```javascript const axios = require('axios'); axios.get('https://example.com/api/v1/users', { params: { page: 1, limit: 10, } }) .then(res => { console.log(res.data); }) .catch(error => { console.error(error); }); ``` This example will send a GET request to the endpoint https://example.com/api/v1/users?page=1&limit=10.


Comments