feat: stabilization + recipe edit/create UI
This commit is contained in:
17
frontend/src/api/client.ts
Normal file
17
frontend/src/api/client.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
const BASE_URL = '/api'
|
||||
|
||||
export async function apiFetch<T>(path: string, options?: RequestInit): Promise<T> {
|
||||
const method = options?.method?.toUpperCase() || 'GET';
|
||||
const headers: Record<string, string> = { ...options?.headers as Record<string, string> };
|
||||
if (['POST', 'PUT', 'PATCH'].includes(method)) {
|
||||
headers['Content-Type'] = headers['Content-Type'] || 'application/json';
|
||||
}
|
||||
const res = await fetch(`${BASE_URL}${path}`, {
|
||||
...options,
|
||||
headers,
|
||||
})
|
||||
if (!res.ok) {
|
||||
throw new Error(`API Error: ${res.status} ${res.statusText}`)
|
||||
}
|
||||
return res.json()
|
||||
}
|
||||
Reference in New Issue
Block a user