Expand description
§wabot-feature-rest-controller
Rust port of wabot-ts/src/feature/{rest-controller,express,http}.
Provides the runtime + axum/tokio integration that the
#[rest_controller] / #[get] / #[post] / #[put] / #[delete]
/ #[middleware] macros target.
Typical wiring:
ⓘ
use std::sync::Arc;
use wabot::prelude::*;
use wabot::register_singletons;
use wabot::rest::*;
#[singleton]
pub struct UserController { ... }
#[rest_controller("/api/users")]
impl UserController {
#[get("/")]
async fn list(&self) -> RestResult<axum::response::Response> { ... }
}
#[tokio::main]
async fn main() -> std::io::Result<()> {
let c = Container::new();
register_singletons!(&c, UserController);
let mut router = axum::Router::new();
router = UserController::register_routes(&c, router);
run_rest_controllers(router, RestServerConfig::from_env()).await
}Re-exports§
pub use error::RestError;pub use error::RestResult;pub use extract::extract_typed;pub use extract::extract_typed_raw;pub use middleware::Middleware;pub use middleware::MiddlewareInstance;pub use request_context::RequestContextLayer;pub use request_context::REQUEST_ID_HEADER;pub use runtime::attach_path_params;pub use runtime::decompose_request;pub use runtime::ok_json;pub use runtime::ok_null;pub use runtime::path_param;pub use runtime::path_params;pub use runtime::run_middlewares;pub use runtime::HandlerContext;pub use runtime::PathParams;pub use runtime::DEFAULT_MAX_BODY;pub use server::rest_app;pub use server::run_rest_controllers;pub use server::serve_on;pub use server::RestServerConfig;pub use axum;
Modules§
- error
- REST error type with HTTP status mapping.
- extract
- Typed request extraction + validation pipeline.
- middleware
- Middleware trait — direct equivalent of wabot-ts
IMiddleware. - rate_
limit - Rate-limit an endpoint. Port of
@rateLimitin wabot-ts. - request_
context - Give every request a correlation id, and carry it through the handler.
- runtime
- Per-request runtime helpers used by the macro-generated handlers.
- server
- HTTP server bootstrap — port of
feature/express+feature/httpin wabot-ts. Same role: take an assembledaxum::Router, bind to a port, serve until told to stop.
Macros§
- rest_
rate_ limit - Declare a rate-limiting middleware type.