1import axios from "axios"
2
3const fetchData = () => {
4return axios.get("https://randomuser.me/api/")
5 .then((response) => console.log(response.data));}
1axios.get("/path", (res) => {
2 res.json(
3}).then(data => console.log(data))
1// Add a request interceptor
2axios.interceptors.request.use(function (config) {
3 // Do something before request is sent
4 return config;
5 }, function (error) {
6 // Do something with request error
7 return Promise.reject(error);
8 });
9
10// Add a response interceptor
11axios.interceptors.response.use(function (response) {
12 // Do something with response data
13 return response;
14 }, function (error) {
15 // Do something with response error
16 return Promise.reject(error);
17 });