38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { apiClient } from "./axios.instance";
|
|
import type { AxiosResponse } from "axios";
|
|
|
|
export interface ApiResponse<T = any> {
|
|
data: T;
|
|
message: string;
|
|
success: boolean;
|
|
}
|
|
|
|
class ApiService {
|
|
async get<T>(url: string, config?: any): Promise<T> {
|
|
const response: AxiosResponse<T> = await apiClient.get(url, config);
|
|
return response.data;
|
|
}
|
|
|
|
async post<T, D = any>(url: string, data?: D, config?: any): Promise<T> {
|
|
const response: AxiosResponse<T> = await apiClient.post(url, data, config);
|
|
return response.data;
|
|
}
|
|
|
|
async put<T, D = any>(url: string, data?: D, config?: any): Promise<T> {
|
|
const response: AxiosResponse<T> = await apiClient.put(url, data, config);
|
|
return response.data;
|
|
}
|
|
|
|
async patch<T, D = any>(url: string, data?: D, config?: any): Promise<T> {
|
|
const response: AxiosResponse<T> = await apiClient.patch(url, data, config);
|
|
return response.data;
|
|
}
|
|
|
|
async delete<T>(url: string, config?: any): Promise<T> {
|
|
const response: AxiosResponse<T> = await apiClient.delete(url, config);
|
|
return response.data;
|
|
}
|
|
}
|
|
|
|
export const apiService = new ApiService();
|