Zach
0
Q:

axios instance

//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))
1
axios.get('/foo')
  .catch(function (error) {
    if (error.response) {
      console.log(error.response.data);
      console.log(error.response.status);
      console.log(error.response.headers);
    }
  });
1
axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
6
const res = await axios.put('https://httpbin.org/put', { hello: 'world' });

res.data.headers['Content-Type']; // application/json;charset=utf-8
3
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
1

New to Communities?

Join the community