commit
This commit is contained in:
14
src/lib/api-client.ts
Normal file
14
src/lib/api-client.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
const BASE_URL = '/api';
|
||||
|
||||
export async function apiClient<T>(endpoint: string, options?: RequestInit): Promise<T> {
|
||||
const res = await fetch(`${BASE_URL}${endpoint}`, {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
...options
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`API error: ${res.status} ${res.statusText}`);
|
||||
}
|
||||
|
||||
return res.json() as Promise<T>;
|
||||
}
|
||||
Reference in New Issue
Block a user