axios response header get code example
Example 1: pass header in axios
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: ERROR_FINDING_USER
})
})
Example 2: send xmlhttprequest with axios
var instance = axios.create({
baseURL: 'https://some-domain.com/api/',
headers: {"X-Requested-With": "XMLHttpRequest"}
});
Example 3: axios put request
const res = await axios.put('https://httpbin.org/put', { hello: 'world' });
res.data.headers['Content-Type'];