Skip to content

Commit e2c7806

Browse files
authored
Merge pull request #13 from maitamdev/feat/api-client
feat(utils): add API client utility
2 parents 9980434 + cc76020 commit e2c7806

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/utils/apiClient.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Simple API client wrapper
2+
interface RequestConfig { method?: string; body?: unknown; headers?: Record<string, string>; }
3+
4+
export async function apiRequest<T>(url: string, config: RequestConfig = {}): Promise<T> {
5+
const { method = 'GET', body, headers = {} } = config;
6+
const response = await fetch(url, {
7+
method, headers: { 'Content-Type': 'application/json', ...headers },
8+
body: body ? JSON.stringify(body) : undefined,
9+
});
10+
if (!response.ok) throw new Error('API Error: ' + response.status);
11+
return response.json();
12+
}
13+

0 commit comments

Comments
 (0)