CODEX_ADK/FRONTEND/lib/api/endpoints/health_endpoint.dart
Svrnty 229a0698a3 Initial commit: CODEX_ADK monorepo
Multi-agent AI laboratory with ASP.NET Core 8.0 backend and Flutter frontend.
Implements CQRS architecture, OpenAPI contract-first API design.

BACKEND: Agent management, conversations, executions with PostgreSQL + Ollama
FRONTEND: Cross-platform UI with strict typing and Result-based error handling

Co-Authored-By: Jean-Philippe Brule <jp@svrnty.io>
2025-10-26 23:12:32 -04:00

60 lines
1.7 KiB
Dart

/// Health check endpoint for API connectivity testing
library;
import '../client.dart';
import '../types.dart';
// =============================================================================
// Health Endpoint
// =============================================================================
/// Extension on CqrsApiClient for health check operations
extension HealthEndpoint on CqrsApiClient {
/// Check if the API is healthy and responding
///
/// Returns a `Result<bool>` where:
/// - Success: true if API is healthy
/// - Error: ApiError with details about the failure
///
/// Example:
/// ```dart
/// final client = CqrsApiClient(config: ApiClientConfig.development);
/// final result = await client.checkHealth();
///
/// result.when(
/// success: (isHealthy) => print('API is healthy: $isHealthy'),
/// error: (error) => print('Health check failed: ${error.message}'),
/// );
/// ```
Future<Result<bool>> checkHealth() async {
return executeQuery<bool>(
endpoint: 'health',
query: const HealthQuery(),
fromJson: (json) => json as bool,
);
}
}
/// Standalone health check function for convenience
///
/// Creates a temporary client instance to perform the health check.
/// Use this when you don't have a client instance readily available.
///
/// Example:
/// ```dart
/// final result = await performHealthCheck();
/// if (result.isSuccess && result.value) {
/// print('API is ready!');
/// }
/// ```
Future<Result<bool>> performHealthCheck({
ApiClientConfig config = ApiClientConfig.development,
}) async {
final client = CqrsApiClient(config: config);
try {
return await client.checkHealth();
} finally {
client.dispose();
}
}