request api with axios code example
Example 1: axios post
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Example 2: axios get status code
axios.get('/foo')
.catch(function (error) {
if (error.response) {
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
}
});
Example 3: axios put
const res = await axios.put('https://httpbin.org/put', { hello: 'world' });
res.data.headers['Content-Type']; // application/json;charset=utf-8