http call axios instance code example
Example 1: axios instance
const getUser = axios.create({
baseURL: 'https://randomuser.me/api/',
timeout: 1000,
headers: {'X-Custom-Header': 'foobar'}
});
getUser().then(response => console.log(response))
Example 2: how to make request with axios
const axios = require('axios');
async function makeGetRequest() {
let res = await axios.get('http://webcode.me');
let data = res.data;
console.log(data);
}
makeGetRequest();
Example 3: axios.create() instance
const instance = axios.create({
baseURL: 'https://some-domain.com/api/',
timeout: 1000,
headers: {'X-Custom-Header': 'foobar'}
});