Sending the bearer token with axios

前端 未结 9 1354
野趣味
野趣味 2020-11-28 21:21

In my react app i am using axios to perform the REST api requests.

But it\'s unable to send the Authorization header with the request.

Here is my co

9条回答
  •  我在风中等你
    2020-11-28 22:08

    You can create config once and use it everywhere.

    const instance = axios.create({
      baseURL: 'https://some-domain.com/api/',
      timeout: 1000,
      headers: {'Authorization': 'Bearer '+token}
    });
    
    instance.get('/path')
    .then(response => {
        return response.data;
    })
    

提交回复
热议问题