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
1axios.get('https://api.github.com/user', {
2 headers: {
3 'Authorization': `token ${access_token}`
4 }
5})
6.then((res) => {
7 console.log(res.data)
8})
9.catch((error) => {
10 console.error(error)
11})
12
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})