| /** | |
| * API service for communicating with FastAPI backend | |
| * Running on http://localhost:8000 | |
| */ | |
| const API_BASE_URL = import.meta.env.VITE_API_URL || ''; | |
| export interface NotificationPayload { | |
| source: string; | |
| message: string; | |
| } | |
| export interface ApiResponse { | |
| intent: string; | |
| data: Record<string, any>; | |
| event: Record<string, any>; | |
| message: string; | |
| } | |
| class ApiClient { | |
| /** | |
| * Send notification to backend | |
| * POST /api/notification | |
| */ | |
| async sendNotification(payload: NotificationPayload): Promise<ApiResponse> { | |
| try { | |
| const response = await fetch(`${API_BASE_URL}/api/notification`, { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify(payload), | |
| }); | |
| if (!response.ok) { | |
| throw new Error(`Backend error: ${response.statusText}`); | |
| } | |
| return await response.json(); | |
| } catch (error) { | |
| console.error('API Error:', error); | |
| throw error; | |
| } | |
| } | |
| /** | |
| * Health check endpoint | |
| * GET /health | |
| */ | |
| async healthCheck(): Promise<boolean> { | |
| try { | |
| const response = await fetch(`${API_BASE_URL}/health`, { | |
| method: 'GET', | |
| }); | |
| return response.ok; | |
| } catch { | |
| return false; | |
| } | |
| } | |
| } | |
| export const apiClient = new ApiClient(); | |