-1

I have an authenticated API from that i want to fetch the data. I am doing this in REACT using Axios.. How to do this?

2
  • Most commonly this is done through the Authorization header Commented Sep 27, 2018 at 9:52
  • Could you please explain clearly i am new bie so..or else can you share the where i can get the clear idea of this?? Commented Sep 27, 2018 at 9:53

2 Answers 2

1

Something like below

const AuthString = 'Bearer '.concat(USER_TOKEN); 
axios.get(URL, { headers: { Authorization: AuthString } })
 .then(response => {
     console.log(response.data);
  })
 .catch((error) => {
     console.log('error ' + error);
  });
Sign up to request clarification or add additional context in comments.

2 Comments

I found the Bearer ans User Token in Post man..What those things are actually?
0

1- You can create something like this if you already have access token.

const authAxios = axios.create({
baseURL: "yourURL",
headers: {
  Authorization: `Bearer ${accessToken}`,
},

});

2- After creating the axios, you can use the created axios when hitting the API:

  authAxios.get("URL").then((res) => {
    return res.data;

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.