Sometimes, we want to send authorization header with Axios and JavaScript.
In this article, we’ll look at how to send authorization header with Axios and JavaScript.
How to send authorization header with Axios and JavaScript?
To send authorization header with Axios and JavaScript, we can set the headers
property in the request options object.
For instance, we write
const response = await axios.get(url, {
headers: {
Authorization: `Bearer ${token}`,
},
});
to make a get request to the url
with axios.get
.
We set the Authorization
header by adding the Authorization
property to headers
.
And we get the response
from the returned promise with await
.
Conclusion
To send authorization header with Axios and JavaScript, we can set the headers
property in the request options object.