const BASE_URL = 'http://localhost:5000'; async function request(method: string, path: string, body?: unknown): Promise { const headers: Record = { 'Content-Type': 'application/json' }; const res = await fetch(`${BASE_URL}${path}`, { method, headers, body: body ? JSON.stringify(body) : undefined, }); if (!res.ok) { const text = await res.text(); throw new Error(text || `HTTP ${res.status}`); } const json = await res.json(); if (json.code !== 0) { throw new Error(json.message || `Error code ${json.code}`); } return json.data as T; } export const api = { get: (path: string) => request('GET', path), post: (path: string, body?: unknown) => request('POST', path, body), put: (path: string, body?: unknown) => request('PUT', path, body), del: (path: string) => request('DELETE', path), };