axios post from data code example
Example 1: header in axios
axios.post('url', {"body":data}, {
headers: {
'Content-Type': 'application/json'
}
}
)
Example 2: axios api post request
import qs from 'qs';
const data = { 'bar': 123 };
const options = {
method: 'POST',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
data: qs.stringify(data),
url,
};
axios(options);
Example 3: 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 4: 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();