Skip to main content

kova_api/
lib.rs

1//! kova-api: HTTP API.
2//!
3//! `GET /health` — liveness probe.
4//! `GET /` — embedded GUI (from `kova-gui`).
5//! The SSE pipeline event stream lands with the engine.
6
7use axum::{routing::get, Json, Router};
8use serde_json::json;
9
10/// Build the API router.
11pub fn router() -> Router {
12    Router::new()
13        .route("/health", get(health))
14        .route("/", get(index))
15}
16
17async fn health() -> Json<serde_json::Value> {
18    Json(json!({
19        "status": "ok",
20        "service": "kova",
21        "version": env!("CARGO_PKG_VERSION"),
22    }))
23}
24
25async fn index() -> String {
26    kova_gui::index_html()
27}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32
33    #[test]
34    fn router_builds() {
35        let _ = router();
36    }
37
38    #[tokio::test]
39    async fn health_payload_is_ok() {
40        let v = health().await.0;
41        assert_eq!(v["status"], "ok");
42        assert_eq!(v["service"], "kova");
43    }
44
45    #[tokio::test]
46    async fn index_serves_embedded_gui() {
47        assert!(index().await.contains("Kova"));
48    }
49}