Skip to main content

wabot_feature_rest_controller/
lib.rs

1//! # wabot-feature-rest-controller
2//!
3//! Rust port of `wabot-ts/src/feature/{rest-controller,express,http}`.
4//! Provides the runtime + axum/tokio integration that the
5//! `#[rest_controller]` / `#[get]` / `#[post]` / `#[put]` / `#[delete]`
6//! / `#[middleware]` macros target.
7//!
8//! Typical wiring:
9//!
10//! ```ignore
11//! use std::sync::Arc;
12//! use wabot::prelude::*;
13//! use wabot::register_singletons;
14//! use wabot::rest::*;
15//!
16//! #[singleton]
17//! pub struct UserController { ... }
18//!
19//! #[rest_controller("/api/users")]
20//! impl UserController {
21//!     #[get("/")]
22//!     async fn list(&self) -> RestResult<axum::response::Response> { ... }
23//! }
24//!
25//! #[tokio::main]
26//! async fn main() -> std::io::Result<()> {
27//!     let c = Container::new();
28//!     register_singletons!(&c, UserController);
29//!
30//!     let mut router = axum::Router::new();
31//!     router = UserController::register_routes(&c, router);
32//!
33//!     run_rest_controllers(router, RestServerConfig::from_env()).await
34//! }
35//! ```
36
37pub mod error;
38pub mod extract;
39pub mod middleware;
40pub mod rate_limit;
41pub mod request_context;
42pub mod runtime;
43pub mod server;
44
45pub use error::{RestError, RestResult};
46pub use extract::{extract_typed, extract_typed_raw};
47pub use middleware::{Middleware, MiddlewareInstance};
48pub use request_context::{RequestContextLayer, REQUEST_ID_HEADER};
49pub use runtime::{
50    attach_path_params, decompose_request, ok_json, ok_null, path_param, path_params,
51    run_middlewares, HandlerContext, PathParams, DEFAULT_MAX_BODY,
52};
53#[cfg(feature = "tls")]
54pub use server::TlsMode;
55pub use server::{rest_app, run_rest_controllers, serve_on, RestServerConfig};
56
57/// Re-export axum so user code can refer to `Json`, `Router`, etc.
58/// through the same import root as the rest of the framework.
59pub use axum;
60
61/// Re-export rustls for the same reason axum is re-exported, with more
62/// at stake: an application that resolves its own rustls can end up
63/// with two copies in one binary, and a `ServerConfig` built against
64/// the wrong one fails to typecheck in a way that reads as nonsense at
65/// the call site.
66#[cfg(feature = "tls")]
67pub use rustls;