axios.get headers code example
Example 1: axios cdn
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
Example 2: axios header authorization
const res = await axios.get('https://httpbin.org/get', {
headers: {
authorization: 'my secret token'
}
});
Example 3: 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 4: header in axios
axios.post('url', {"body":data}, {
headers: {
'Content-Type': 'application/json'
}
}
)
Example 5: headers in axios.get
const axios = require('axios');
const res = await axios.get('https://httpbin.org/get', {
headers: {
'Test-Header': 'test-value'
}
});
res.data.headers['Test-Header'];
Example 6: axios post with header
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
},
headers: {'Authorization': 'Bearer ...'}
});