Answer the question
In order to leave comments, you need to log in
Dynamic method in AxiosInstance with Typescript?
There is an instance of axios
export default function apiClient(app?: ClientApplication<any>): AxiosInstance {
const baseUrl = 'blablabla'
const apiClient = axios.create({
baseURL: baseUrl,
})
apiClient.interceptors.request.use(
function (config) {
if (app !== null) {
return getSessionToken(app!)
.then((token) => {
config.headers!['Authorization'] = `Bearer ${token}`;
return config;
});
} else {
return config;
}
}
);
return apiClient;
}
await apiClient.post(...)
await apiClient.get(...)
await apiClient[workMode]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question