Generic Example: API Client
This example shows a minimal src/lib/apiClient.ts that calls the BFF only.
// src/lib/apiClient.ts
export async function apiFetch<T>(path: string, init?: RequestInit): Promise<T> {
const res = await fetch(path, {
...init,
credentials: "include",
headers: {
...(init?.headers ?? {}),
"content-type": "application/json",
},
});
const body = await res.json().catch(() => ({}));
if (!res.ok) throw body;
return body as T;
}