async function request(url: string, init?: RequestInit): Promise { const res = await fetch(url, init); if (!res.ok) { const body = await res.json().catch(() => ({})) as { error?: string }; throw new Error(body.error ?? `HTTP ${res.status}`); } return res.json() as Promise; } export const api = { get: (url: string) => request(url), post: (url: string, body: unknown) => request(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }), patch: (url: string, body: unknown) => request(url, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }), delete: (url: string) => request(url, { method: "DELETE" }), };