PluginProbe ʕ •ᴥ•ʔ
Hostinger Tools / 3.0.72
Hostinger Tools v3.0.72
3.0.72 3.0.71 3.0.70 3.0.69 3.0.68 3.0.67 3.0.66 1.8.1 1.8.2 1.8.3 1.9.1 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.4 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 3.0.0 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.18 3.0.19 3.0.2 3.0.20 3.0.21 3.0.22 3.0.23 3.0.24 3.0.25 3.0.26 3.0.27 3.0.28 3.0.29 3.0.3 3.0.30 3.0.31 3.0.32 3.0.33 3.0.34 3.0.35 3.0.36 3.0.37 3.0.38 3.0.39 3.0.4 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.0.46 3.0.47 3.0.48 3.0.49 3.0.5 3.0.50 3.0.51 3.0.52 3.0.53 3.0.54 3.0.55 3.0.56 3.0.57 3.0.58 3.0.59 3.0.6 3.0.60 3.0.61 3.0.62 3.0.65 3.0.7 3.0.8 3.0.9 trunk 1.8.0
hostinger / vue-frontend / src / utils / services / httpService.ts
hostinger / vue-frontend / src / utils / services Last commit date
httpService.ts 10 months ago index.ts 1 year ago snakeCamelService.ts 10 months ago
httpService.ts
71 lines
1 import axios, {
2 AxiosRequestConfig,
3 AxiosResponse,
4 InternalAxiosRequestConfig
5 } from "axios";
6
7 import { asyncCall } from "@/utils/helpers";
8 import { camelToSnakeObj, snakeToCamelObj } from "@/utils/services";
9
10 const TIMEOUT_TIME = 120_000;
11
12 export const axiosInstance = axios.create({
13 timeout: TIMEOUT_TIME,
14 withCredentials: false,
15 headers: {
16 Accept: "application/json;charset=UTF-8",
17 "Content-Type": "application/json;charset=UTF-8"
18 }
19 });
20
21 // REQUEST INTERCEPTOR - camel to snake
22 axiosInstance.interceptors.request.use((req: InternalAxiosRequestConfig) => {
23 if ((req as InternalAxiosRequestConfig & { plain?: boolean }).plain)
24 return req;
25
26 if (req.data) {
27 req.data = camelToSnakeObj(req.data);
28 }
29
30 if (req.params) {
31 req.params = camelToSnakeObj(req.params);
32 }
33
34 return req;
35 });
36
37 axiosInstance.interceptors.response.use(
38 (res: AxiosResponse) => {
39 const transformedResponse = snakeToCamelObj({
40 ...res,
41 data: res.data
42 });
43
44 return transformedResponse as AxiosResponse;
45 },
46 (error: Error) => Promise.reject(error)
47 );
48
49 const httpService = {
50 get<T>(url: string, config?: AxiosRequestConfig) {
51 return asyncCall<T>(axiosInstance.get(url, config));
52 },
53 post<T>(url: string, data?: unknown, config?: AxiosRequestConfig) {
54 return asyncCall<T>(axiosInstance.post(url, data, config));
55 },
56 put<T>(url: string, data?: unknown, config?: AxiosRequestConfig) {
57 return asyncCall<T>(axiosInstance.put(url, data, config));
58 },
59 patch<T>(url: string, data?: unknown, config?: AxiosRequestConfig) {
60 return asyncCall<T>(axiosInstance.patch(url, data, config));
61 },
62 delete<T>(url: string, config?: AxiosRequestConfig) {
63 return asyncCall<T>(axiosInstance.delete(url, config));
64 },
65 request<T>(config: AxiosRequestConfig) {
66 return asyncCall<T>(axiosInstance(config));
67 }
68 };
69
70 export default httpService;
71