/** * HTTP API Client for Cloud Deployment * Replaces Tauri IPC with REST API calls */ export interface ApiResponse { success: boolean; data?: T; error?: string; } /** * Base API request function */ async function apiRequest( endpoint: string, options?: RequestInit ): Promise { const response = await fetch(endpoint, { headers: { 'Content-Type': 'application/json', ...options?.headers, }, ...options, }); if (!response.ok) { const errorText = await response.text(); throw new Error(errorText || `HTTP ${response.status}`); } const result: ApiResponse = await response.json(); if (!result.success) { throw new Error(result.error || 'Unknown error'); } return result.data as T; } /** * API client with convenience methods */ export const api = { /** * GET request */ get: (url: string): Promise => apiRequest(url), /** * POST request */ post: (url: string, body?: unknown): Promise => apiRequest(url, { method: 'POST', body: body ? JSON.stringify(body) : undefined, }), /** * DELETE request */ delete: (url: string): Promise => apiRequest(url, { method: 'DELETE', }), /** * PUT request */ put: (url: string, body?: unknown): Promise => apiRequest(url, { method: 'PUT', body: body ? JSON.stringify(body) : undefined, }), }; export default api;