Skip to main content

capy_http/
lib.rs

1//! Thin Axum routing and response conveniences.
2
3mod routes;
4
5pub use axum::Json;
6use axum::{
7    http::StatusCode,
8    response::{IntoResponse, Response},
9};
10pub use routes::{RouteInfo, Routes};
11use serde::Serialize;
12
13/// A JSON response with HTTP 201 Created.
14#[derive(Debug, Clone)]
15pub struct Created<T>(pub T);
16
17impl<T: Serialize> IntoResponse for Created<T> {
18    fn into_response(self) -> Response {
19        (StatusCode::CREATED, Json(self.0)).into_response()
20    }
21}
22
23/// An empty response with HTTP 204 No Content.
24#[derive(Debug, Clone, Copy)]
25pub struct NoContent;
26
27impl IntoResponse for NoContent {
28    fn into_response(self) -> Response {
29        StatusCode::NO_CONTENT.into_response()
30    }
31}
32
33/// The default health response; it deliberately performs no database query.
34pub async fn health() -> Json<serde_json::Value> {
35    Json(serde_json::json!({ "status": "ok" }))
36}