//lets you create custom pre-configured instance const getUser = axios.create({ baseURL: 'https://randomuser.me/api/', //custom config: timeout: 1000, headers: {'X-Custom-Header': 'foobar'} }); //to use later like this getUser().then(response => console.log(response))
axios.get('/foo') .catch(function (error) { if (error.response) { console.log(error.response.data); console.log(error.response.status); console.log(error.response.headers); } });
axios.post('/user', { firstName: 'Fred', lastName: 'Flintstone' }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
const res = await axios.put('https://httpbin.org/put', { hello: 'world' }); res.data.headers['Content-Type']; // application/json;charset=utf-8
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>