axios headers authorization code example
Example 1: axios header authorization
const res = await axios.get('https://httpbin.org/get', {
headers: {
authorization: 'my secret token'
}
});
Example 2: add authorization header axios
const res = await axios.get('https://httpbin.org/get', {
headers: {
'Authorization': 'my secret token'
}
});
Example 3: axios set authorization header
const username = ''
const password = ''
const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64')
const url = 'https://...'
axios.post(url, {
headers: {
'Authorization': `Basic ${token}`
}
})
Example 4: send token in axios header
const username = ''
const password = ''
const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64')
const url = 'https://...'
const data = {
...
}
axios.post(url, data, {
headers: {
'Authorization': `Basic ${token}`
},
})
Example 5: axios default headers authorization
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;