lmrc_http_common/
lib.rs

1//! # lmrc-http-common
2//!
3//! Common HTTP utilities and patterns for LMRC Stack applications.
4//!
5//! This library provides reusable components for building Axum-based HTTP services:
6//! - Standard error types and response wrappers
7//! - Reusable middleware (CORS, logging, tracing)
8//! - Authentication utilities (JWT, session management, password hashing)
9//! - Configuration management (server, database)
10//! - Health check framework
11//! - Validated request extractors
12//! - Server bootstrap utilities
13//!
14//! ## Features
15//!
16//! - `auth` (default): Enable authentication utilities (JWT, bcrypt, sessions)
17//! - `validation` (default): Enable request validation helpers
18//! - `server`: Enable server bootstrap utilities (tracing-subscriber, dotenvy)
19//!
20//! ## Example
21//!
22//! ```rust
23//! use lmrc_http_common::{
24//!     error::{HttpError, HttpResult},
25//!     response::SuccessResponse,
26//! };
27//! use axum::{Json, response::IntoResponse};
28//!
29//! async fn handler() -> HttpResult<impl IntoResponse> {
30//!     let data = vec!["item1", "item2"];
31//!     Ok(SuccessResponse::new(data))
32//! }
33//! ```
34//!
35//! ## Quick Start Server
36//!
37//! ```rust,no_run
38//! # #[cfg(feature = "server")]
39//! # {
40//! use axum::{Router, routing::get};
41//! use lmrc_http_common::server::quick_start;
42//!
43//! #[tokio::main]
44//! async fn main() -> anyhow::Result<()> {
45//!     let router = Router::new().route("/health", get(|| async { "OK" }));
46//!     quick_start("myapp", router, 8080).await?;
47//!     Ok(())
48//! }
49//! # }
50//! ```
51
52pub mod config;
53pub mod error;
54pub mod health;
55pub mod response;
56pub mod middleware;
57
58#[cfg(feature = "auth")]
59pub mod auth;
60
61#[cfg(feature = "validation")]
62pub mod extractors;
63
64#[cfg(feature = "server")]
65pub mod server;
66
67// Re-export commonly used types
68pub use error::{ErrorResponse, HttpError, HttpResult};
69pub use response::{
70    CreatedResponse, EmptyResponse, PaginatedResponse, PaginationMeta, SuccessResponse,
71};
72pub use config::{ConfigLoader, ServerConfig, DatabaseConfig, ConfigError, ConfigResult};
73pub use health::{HealthStatus, HealthCheck, HealthChecker, Status, CheckResult};
74
75#[cfg(feature = "validation")]
76pub use extractors::{ValidatedJson, ValidatedQuery};