karbon_framework/http/
response.rs1use axum::http::StatusCode;
2use axum::response::IntoResponse;
3use serde::Serialize;
4
5pub struct JsonResponse;
7
8impl JsonResponse {
9 pub fn ok<T: Serialize>(data: T) -> impl IntoResponse {
11 (StatusCode::OK, axum::Json(data))
12 }
13
14 pub fn created<T: Serialize>(data: T) -> impl IntoResponse {
16 (StatusCode::CREATED, axum::Json(data))
17 }
18
19 pub fn no_content() -> impl IntoResponse {
21 StatusCode::NO_CONTENT
22 }
23
24 pub fn message(status: StatusCode, msg: &str) -> impl IntoResponse {
26 (
27 status,
28 axum::Json(serde_json::json!({ "message": msg })),
29 )
30 }
31
32 pub fn success(msg: &str) -> impl IntoResponse {
34 Self::message(StatusCode::OK, msg)
35 }
36}