Passing headers with axios POST request

When using Axios, in order to pass custom headers, supply an object containing the headers as the last argument Modify your Axios request like: const headers = { ‘Content-Type’: ‘application/json’, ‘Authorization’: ‘JWT fefege…’ } axios.post(Helper.getUserAPI(), data, { headers: headers }) .then((response) => { dispatch({ type: FOUND_USER, data: response.data[0] }) }) .catch((error) => { dispatch({ type: … Read more

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