close

How to send authorization header with axios

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to send authorization header with axios in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How to send authorization header with axios ?

  1. How to send authorization header with axios ?

    to send authorization header with axios This has worked for me:
    let webApiUrl = 'example.com/getStuff'; let tokenStr = 'xxyyzz'; axios.get(webApiUrl, { headers: {"Authorization" : `Bearer ${tokenStr}`} });

  2. How to send authorization header with axios ?

    to send authorization header with axios This has worked for me:
    let webApiUrl = 'example.com/getStuff'; let tokenStr = 'xxyyzz'; axios.get(webApiUrl, { headers: {"Authorization" : `Bearer ${tokenStr}`} });

Method 1

This has worked for me:

let webApiUrl = 'example.com/getStuff';
let tokenStr = 'xxyyzz';
axios.get(webApiUrl, { headers: {"Authorization" : `Bearer ${tokenStr}`} });

Method 2

Try this :

axios.get(
    url,
    {headers: {
        "name" : "value"
      }
    }
  )
  .then((response) => {
      var response = response.data;
    },
    (error) => {
      var status = error.response.status
    }
  );

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment