Axios get access to response header fields

In case of CORS requests, browsers can only access the following response headers by default: Cache-Control Content-Language Content-Type Expires Last-Modified Pragma If you would like your client app to be able to access other headers, you need to set the Access-Control-Expose-Headers header on the server: Access-Control-Expose-Headers: Access-Token, Uid

How to download files using axios

A more general solution axios({ url: ‘http://api.dev/file-download’, //your url method: ‘GET’, responseType: ‘blob’, // important }).then((response) => { const url = window.URL.createObjectURL(new Blob([response.data])); const link = document.createElement(‘a’); link.href = url; link.setAttribute(‘download’, ‘file.pdf’); //or any other extension document.body.appendChild(link); link.click(); }); Check out the quirks at https://gist.github.com/javilobo8/097c30a233786be52070986d8cdb1743 Full credits to: https://gist.github.com/javilobo8

Make Axios send cookies in its requests automatically

You can use withCredentials property. XMLHttpRequest from a different domain cannot set cookie values for their own domain unless withCredentials is set to true before making the request. axios.get(BASE_URL + ‘/todos’, { withCredentials: true }); Also its possible to force credentials to every Axios requests axios.defaults.withCredentials = true Or using credentials for some of the … Read more

axios post request to send form data

You can post axios data by using FormData() like: var bodyFormData = new FormData(); And then add the fields to the form you want to send: bodyFormData.append(‘userName’, ‘Fred’); If you are uploading images, you may want to use .append bodyFormData.append(‘image’, imageFile); And then you can use axios post method (You can amend it accordingly) axios({ … Read more