export interface RequestOptions { headers?: Record; queryParams?: Record; body?: any; } async function buildUrl(url: string, queryParams?: Record): Promise { if (!queryParams) return url; const params = new URLSearchParams(queryParams as Record).toString(); return `${url}?${params}`; } async function request(method: string, url: string, options: RequestOptions = {}): Promise { const fullUrl = await buildUrl(url, options.queryParams); const fetchOptions: RequestInit = { method, headers: { 'Content-Type': 'application/json', ...(options.headers || {}) }, body: options.body ? JSON.stringify(options.body) : undefined }; const response = await fetch(fullUrl, fetchOptions); if (!response.ok) { const text = await response.text(); throw new Error(`HTTP ${response.status}: ${text}`); } return response.json() as Promise; } export function get(url: string, options?: Omit): Promise { return request('GET', url, options || {}); } export function post(url: string, options?: Omit & { body: any }): Promise { return request('POST', url, options as RequestOptions); } export function put(url: string, options?: Omit & { body: any }): Promise { return request('PUT', url, options as RequestOptions); } export function del(url: string, options?: Omit): Promise { return request('DELETE', url, options || {}); }