generated from fahricansecer/boilerplate-fe
Initial commit
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { clientMap } from '@/lib/api/client-map';
|
||||
import { Method } from 'axios';
|
||||
|
||||
interface ApiRequestOptions {
|
||||
url: string;
|
||||
client: keyof typeof clientMap;
|
||||
method?: Method;
|
||||
data?: any;
|
||||
params?: Record<string, any>;
|
||||
}
|
||||
|
||||
export async function apiRequest<T = any>(options: ApiRequestOptions): Promise<T> {
|
||||
const { url, client, method = 'get', data, params } = options;
|
||||
const clientInstance = clientMap[client];
|
||||
|
||||
if (!url || !clientInstance) {
|
||||
throw new Error(`Invalid API request: ${client} - ${url}`);
|
||||
}
|
||||
|
||||
const response = await clientInstance.request<T>({ method, url, data, params });
|
||||
return response.data;
|
||||
}
|
||||
Reference in New Issue
Block a user