# hostinger/3.0.6/vue-frontend/src/utils/services/httpService.ts

Hostinger Tools, version 3.0.6. 64 lines.

- Page: https://pluginprobe.com/plugins/hostinger/3.0.6/code/vue-frontend/src/utils/services/httpService.ts
- Raw: https://pluginprobe.com/plugins/hostinger/3.0.6/raw/vue-frontend/src/utils/services/httpService.ts
- Modified: 2024-06-04T12:01:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/hostinger/3.0.6/code/vue-frontend/src/utils/services/httpService.ts#L10-L20`.

```typescript
import axios from "axios";
import { AxiosRequestConfig } from "axios";
import { camelToSnakeObj, snakeToCamelObj } from "@/utils/services";
import { asyncCall } from "@/utils/helpers";

const TIMEOUT_TIME = 120_000;

export const axiosInstance = axios.create({
  timeout: TIMEOUT_TIME,
  withCredentials: false,
  headers: {
    Accept: "application/json;charset=UTF-8",
    "Content-Type": "application/json;charset=UTF-8",
  },
});

// REQUEST INTERCEPTOR - camel to snake
axiosInstance.interceptors.request.use((req: any) => {
  if (req.plain) return req;

  if (req.data) {
    req.data = camelToSnakeObj(req.data);
  }

  if (req.params) {
    req.params = camelToSnakeObj(req.params);
  }

  return req;
});

axiosInstance.interceptors.response.use(
  (res: any) => {
    return snakeToCamelObj({
      ...res,
      data: res.data,
    });
  },
  (error: Error) => Promise.reject(error)
);

const httpService = {
  get<T>(url: string, config?: AxiosRequestConfig) {
    return asyncCall<T>(axiosInstance.get(url, config));
  },
  post<T>(url: string, data?: any, config?: AxiosRequestConfig) {
    return asyncCall<T>(axiosInstance.post(url, data, config));
  },
  put<T>(url: string, data?: any, config?: AxiosRequestConfig) {
    return asyncCall<T>(axiosInstance.put(url, data, config));
  },
  patch<T>(url: string, data?: any, config?: AxiosRequestConfig) {
    return asyncCall<T>(axiosInstance.patch(url, data, config));
  },
  delete<T>(url: string, config?: AxiosRequestConfig) {
    return asyncCall<T>(axiosInstance.delete(url, config));
  },
  request<T>(config: AxiosRequestConfig) {
    return asyncCall<T>(axiosInstance(config));
  },
};

export default httpService;

```
