capy-http 0.1.0

Axum routing and JSON response conveniences for Capy.
Documentation
//! Thin Axum routing and response conveniences.

mod routes;

pub use axum::Json;
use axum::{
    http::StatusCode,
    response::{IntoResponse, Response},
};
pub use routes::{RouteInfo, Routes};
use serde::Serialize;

/// A JSON response with HTTP 201 Created.
#[derive(Debug, Clone)]
pub struct Created<T>(pub T);

impl<T: Serialize> IntoResponse for Created<T> {
    fn into_response(self) -> Response {
        (StatusCode::CREATED, Json(self.0)).into_response()
    }
}

/// An empty response with HTTP 204 No Content.
#[derive(Debug, Clone, Copy)]
pub struct NoContent;

impl IntoResponse for NoContent {
    fn into_response(self) -> Response {
        StatusCode::NO_CONTENT.into_response()
    }
}

/// The default health response; it deliberately performs no database query.
pub async fn health() -> Json<serde_json::Value> {
    Json(serde_json::json!({ "status": "ok" }))
}