axios create API token code example
Example 1: autherization token in axios
const api = 'your api';
const token = JSON.parse(sessionStorage.getItem('data'));
const token = user.data.id;
axios.get(api , { headers: {"Authorization" : `Bearer ${token}`} })
.then(res => {
console.log(res.data);
.catch((error) => {
console.log(error)
});
Example 2: axios post with header
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
},
headers: {'Authorization': 'Bearer ...'}
});