1// Send a GET request with the authorization header set to
2// the string 'my secret token'
3const res = await axios.get('https://httpbin.org/get', {
4 headers: {
5 'Authorization': 'my secret token'
6 }
7});
1import axios from "axios";
2
3const httpClient = axios.create({
4 baseURL: "http://youradress",
5 // baseURL: process.env.APP_API_BASE_URL,
6});
7
8httpClient.interceptors.request.use(function (config) {
9 const token = localStorage.getItem('token');
10 config.headers.Authorization = token ? `Bearer ${token}` : '';
11 return config;
12});
13
1const username = ''
2const password = ''
3
4const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64')
5
6const url = 'https://...'
7
8axios.post(url, {
9 headers: {
10 'Authorization': `Basic ${token}`
11 }
12})
13
1const username = ''
2const password = ''
3
4const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64')
5
6const url = 'https://...'
7const data = {
8 ...
9}
10
11axios.post(url, data, {
12 headers: {
13 'Authorization': `Basic ${token}`
14 },
15})
1await axios.post(session_url, {}, {
2 auth: {
3 username: uname,
4 password: pass
5 }
6});
7