Crate lmrc_http_common

Crate lmrc_http_common 

Source
Expand description

§lmrc-http-common

Common HTTP utilities and patterns for LMRC Stack applications.

This library provides reusable components for building Axum-based HTTP services:

  • Standard error types and response wrappers
  • Reusable middleware (CORS, logging, tracing)
  • Authentication utilities (JWT, session management, password hashing)
  • Configuration management (server, database)
  • Health check framework
  • Validated request extractors
  • Server bootstrap utilities

§Features

  • auth (default): Enable authentication utilities (JWT, bcrypt, sessions)
  • validation (default): Enable request validation helpers
  • server: Enable server bootstrap utilities (tracing-subscriber, dotenvy)

§Example

use lmrc_http_common::{
    error::{HttpError, HttpResult},
    response::SuccessResponse,
};
use axum::{Json, response::IntoResponse};

async fn handler() -> HttpResult<impl IntoResponse> {
    let data = vec!["item1", "item2"];
    Ok(SuccessResponse::new(data))
}

§Quick Start Server

use axum::{Router, routing::get};
use lmrc_http_common::server::quick_start;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let router = Router::new().route("/health", get(|| async { "OK" }));
    quick_start("myapp", router, 8080).await?;
    Ok(())
}

Re-exports§

pub use error::ErrorResponse;
pub use error::HttpError;
pub use error::HttpResult;
pub use response::CreatedResponse;
pub use response::EmptyResponse;
pub use response::PaginatedResponse;
pub use response::PaginationMeta;
pub use response::SuccessResponse;
pub use config::ConfigLoader;
pub use config::ServerConfig;
pub use config::DatabaseConfig;
pub use config::ConfigError;
pub use config::ConfigResult;
pub use health::HealthStatus;
pub use health::HealthCheck;
pub use health::HealthChecker;
pub use health::Status;
pub use health::CheckResult;
pub use extractors::ValidatedJson;
pub use extractors::ValidatedQuery;

Modules§

auth
Authentication utilities for HTTP services
config
Configuration management utilities
error
Common error types for HTTP services
extractors
Request extractors with automatic validation
health
Health check utilities
middleware
Reusable middleware for Axum applications
response
Standard HTTP response wrappers

Macros§

app_error
Macro for creating app-specific error types that wrap HttpError