This content originally appeared on CodeSource.io and was authored by Pandu Rijal Pasa
In this article, we will learn how to use Axios Header on your request.
There is a slight difference in using the Axios Header on GET
method compared to others.
Let’s say we want to put an Authorization header on our request, we can pass the header object as the second argument of the request.
// set headers for GET method
axios.get('https://yourdomain.com/api', {
headers: {
Authorization: 'Bearer ' + token
}
})
For the POST, PUT and also DELETE method, we have to pass the headers object as the third argument because the second one will be used as a payload object. For example, this one is for the POST method:
// set headers for POST method
const payload = {}
axios.post('https://yourdomain.com/api', payload, {
headers: {
Authorization: 'Bearer ' + token
}
})
The post How To Use Axios Header On Your Request appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Pandu Rijal Pasa
Pandu Rijal Pasa | Sciencx (2021-02-21T13:42:57+00:00) How To Use Axios Header On Your Request. Retrieved from https://www.scien.cx/2021/02/21/how-to-use-axios-header-on-your-request/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.