Skip to main content

capy_http/
lib.rs

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