jder_axum/lib.rs
1//! # JDER axum
2//!
3//! A response builder for axum.
4//!
5//! This package includes different axum response builders,
6//! extractors and layers based on the JSON response structure specified in
7//! [JSON Data Errors Response (JDER)](https://github.com/jderstd/spec).
8//! With the builders and extractors provided, various kinds of
9//! responses can be created easily instead of sending plain text responses.
10//!
11//! ## Usage
12//!
13//! To create a JSON response, use
14//! [`CreateJsonResponse`](response::json::CreateJsonResponse):
15//!
16//! ```no_run
17//! use jder_axum::response::{
18//! Response,
19//! json::CreateJsonResponse
20//! };
21//! use serde::Serialize;
22//!
23//! #[derive(Serialize)]
24//! struct RouteResponseData {
25//! title: String,
26//! }
27//!
28//! async fn route() -> Response {
29//! CreateJsonResponse::success::<RouteResponseData>()
30//! .data(RouteResponseData {
31//! title: "Title".to_string(),
32//! })
33//! .create()
34//! }
35//! ```
36//!
37//! If no data is needed, use
38//! [`dataless`](response::json::CreateJsonResponse::dataless)
39//! function instead:
40//!
41//! ```no_run
42//! use jder_axum::response::{
43//! Response,
44//! json::CreateJsonResponse
45//! };
46//!
47//! async fn route() -> Response {
48//! CreateJsonResponse::dataless().create()
49//! }
50//! ```
51//!
52//! For returning content other than JSON, use
53//! [`CreateResponse`](response::CreateResponse):
54//!
55//! ```no_run
56//! use axum::http::header;
57//! use jder_axum::response::{
58//! Response,
59//! CreateResponse
60//! };
61//! use serde::Serialize;
62//!
63//! async fn route() -> Response {
64//! CreateResponse::success()
65//! .header(header::CONTENT_TYPE, "text/plain")
66//! .body("hi")
67//! .create()
68//! }
69//! ```
70
71pub mod extract;
72
73pub mod layers;
74
75pub mod response;