Skip to content

Commit 4cf21b4

Browse files
committed
feat: add a simple health check route
1 parent 1af3851 commit 4cf21b4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use aide::{
77
};
88
use axum::{
99
extract::{MatchedPath, Request},
10-
http::Method,
10+
http::{self, Method},
1111
Extension, Router,
1212
};
1313
use axum_prometheus::PrometheusMetricLayer;
@@ -31,6 +31,7 @@ pub mod routes;
3131
pub const DOCS_ROUTE: &str = "/v0/docs";
3232
pub const WONDERS_ROUTE: &str = "/v0/wonders";
3333
pub const METRICS_ROUTE: &str = "/metrics";
34+
pub const HEALTH_ROUTE: &str = "/health";
3435

3536
pub fn get_app() -> Router {
3637
// API docs generation
@@ -62,6 +63,10 @@ pub fn get_app() -> Router {
6263
.nest_api_service(WONDERS_ROUTE, wonders::routes())
6364
.nest_api_service(DOCS_ROUTE, docs::routes())
6465
.api_route(METRICS_ROUTE, get(|| async move { metric_handle.render() }))
66+
.api_route(
67+
HEALTH_ROUTE,
68+
get(|| async { (http::StatusCode::OK, "Healthy!") }),
69+
)
6570
.fallback(handler_404)
6671
.finish_api_with(&mut api, api_docs)
6772
// Docs generation

tests/routes_misc.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use pretty_assertions::assert_eq;
2-
use world_wonders_api::METRICS_ROUTE;
2+
use world_wonders_api::{HEALTH_ROUTE, METRICS_ROUTE};
33

44
mod common;
55
use common::get_server;
@@ -8,6 +8,11 @@ use common::get_server;
88
async fn test_routes_misc() {
99
let server = get_server();
1010

11+
// HEALTH
12+
let response = server.get(HEALTH_ROUTE).await;
13+
response.assert_status_ok();
14+
response.assert_text_contains("Healthy!");
15+
1116
// 404
1217
let response = server.get("not-a-route").await;
1318
response.assert_status_not_found();

0 commit comments

Comments
 (0)