Files
storkit/server/src/http/health.rs

49 lines
990 B
Rust
Raw Normal View History

2026-02-16 16:24:21 +00:00
use poem::handler;
use poem_openapi::{Object, OpenApi, Tags, payload::Json};
use serde::Serialize;
2026-02-16 16:24:21 +00:00
2026-02-16 16:55:59 +00:00
/// Health check endpoint.
///
/// Returns a static "ok" response to indicate the server is running.
2026-02-16 16:24:21 +00:00
#[handler]
pub fn health() -> &'static str {
"ok"
}
#[derive(Tags)]
enum HealthTags {
Health,
}
#[derive(Serialize, Object)]
pub struct HealthStatus {
status: String,
}
pub struct HealthApi;
#[OpenApi(tag = "HealthTags::Health")]
impl HealthApi {
/// Health check endpoint.
///
/// Returns a JSON status object to confirm the server is running.
#[oai(path = "/health", method = "get")]
async fn health(&self) -> Json<HealthStatus> {
Json(HealthStatus {
status: "ok".to_string(),
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn api_health_returns_ok_status() {
let api = HealthApi;
let response = api.health().await;
assert_eq!(response.0.status, "ok");
}
}