File size: 1,320 Bytes
4b7573c 401224b 4b7573c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | /**
* 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();
|