Skip to main content

rust_webx/
lib.rs

1// rust-webx —Umbrella crate for the Rust WebApi framework.
2// Re-exports all types for a unified `use rust_webx::*` experience.
3
4// --- Core traits ---
5pub use rust_webx_core::app::IHost;
6pub use rust_webx_core::auth::{
7    IAuthenticationHandler, IAuthorizationPolicy, IClaims, IDynamicAuthorizer,
8};
9pub use rust_webx_core::cache::{
10    cache_ext::DistributedCacheExtensions,
11    options::DistributedCacheEntryOptions,
12    trait_def::{CacheError, IDistributedCache},
13};
14pub use rust_webx_core::config::{
15    bind_config, bind_root, load_appsettings, AppOptions, AppSection, CorsSection, IAppOptions,
16    JwtSection, MetricsSection, RateLimitSection, TlsSection,
17};
18pub use rust_webx_core::error::{Error, Result};
19pub use rust_webx_core::handler::{IClaimsCarrier, IEventHandler, IHostedService, IRequestHandler};
20pub use rust_webx_core::http::{
21    read_json_body, write_json_response, FromHttpContext, HttpStatus, IClaimsExt, IHttpContext,
22    IHttpRequest, IHttpResponse, Json,
23};
24pub use rust_webx_core::mediator::{IEventRequest, IMediator, IRequest};
25pub use rust_webx_core::middleware::IMiddleware;
26pub use rust_webx_core::mode::AppMode;
27pub use rust_webx_core::pagination::{PagedRequest, PagedResponse};
28pub use rust_webx_core::paths::{app_base, looks_like_app_base};
29pub use rust_webx_core::mediator::build_pipeline_chain;
30pub use rust_webx_core::pipeline::{BoxedNextFn, BoxedPipelineFuture, IPipelineBehavior};
31pub use rust_webx_core::problem::{FieldError, ProblemDetails};
32pub use rust_webx_core::route::diagnostics::{
33    format_route_diagnostics, orphan_handlers, orphan_routes, route_snapshots,
34};
35pub use rust_webx_core::request_context::RequestContext;
36pub use rust_webx_core::routing::{HttpMethod, IEndpoint, IRouter, RouteMeta};
37
38// --- DI extensions ---
39pub use rust_webx_core::route::ext::{is_mediator_active, should_scan_endpoints, IServiceCollectionExt};
40pub use rust_webx_core::route::scan::{
41    global_provider, set_global_provider, HandlerCache, HandlerEntry, HandlerRegistration,
42    HandlerRegistry, ParamMeta, ResponseData, RouteDispatch, RouteEntry,
43};
44
45// --- HTTP layer ---
46pub use rust_webx_host::auth_jwt::{init_jwt_secret, jwt_middleware, jwt_secret, JwtAuth, JwtClaims};
47pub use rust_webx_host::authz::{
48    collect_authorizers, resource_auth_middleware, AuthorizerSet, ResourceAuthorization,
49};
50pub use rust_webx_host::compression::{compress_gzip, CompressionConfig, CompressionMiddleware};
51pub use rust_webx_host::context::{HttpContext, HttpRequest, HttpResponse};
52pub use rust_webx_host::cors::{CorsConfig, CorsMiddleware};
53pub use rust_webx_host::endpoint::{
54    ControllerEndpoint, RequestEndpoint, StaticHtmlEndpoint, StaticJsonEndpoint,
55};
56pub use rust_webx_host::health::{HealthCheckEntry, HealthCheckFn, HealthCheckRegistry, HealthStatus};
57pub use rust_webx_host::memory_cache::MemoryCache;
58pub use rust_webx_host::pipeline::{HandlerFn, MiddlewarePipeline};
59pub use rust_webx_host::rate_limit::{RateLimitMiddleware, RateLimiter};
60pub use rust_webx_host::request_id::RequestIdMiddleware;
61pub use rust_webx_host::request_tracing::RequestTracing;
62pub use rust_webx_host::router::Router;
63pub use rust_webx_host::security_headers::SecurityHeadersMiddleware;
64pub use rust_webx_host::diagnostics::log_startup_diagnostics;
65pub use rust_webx_host::server::{Host, HostAppBuilder, HostBuilder, Server, ServerHandle};
66pub use rust_webx_host::timing::TimingMiddleware;
67#[cfg(feature = "testing")]
68pub use rust_webx_host::testing::{free_port, spawn, spawn_with_health, wait_until_ready, TestServer};
69
70// --- Mediator ---
71pub use rust_webx_core::mediator::Mediator;
72
73// --- Web (SPA) ---
74pub use rust_webx_spa::SpaMiddleware;
75
76// --- OpenAPI ---
77pub use rust_webx_openapi::{generate_openapi_spec, APIUI_HTML};
78
79// --- Macros ---
80pub use rust_webx_macros::{
81    authorize, claims, delete, endpoint, from_body, from_query, from_route,
82    get, handler, post, put,
83};
84
85// --- Re-export rust_dix (for manual registration, #[inject] auto-registration, and module blocks) ---
86pub use rust_dix;
87pub use rust_dix::inject;
88pub use rust_dix::ScopeFactory;
89pub use rust_dix_macros;
90pub use rust_dix_macros::{module, Inject};
91
92// --- Re-export common dependencies ---
93pub use async_trait::async_trait;
94pub use hyper;
95pub use serde;
96pub use serde_json;
97pub use tokio;
98
99// =========================================================================
100// Convenience macro: register_handlers!
101//
102// Generates chained .singleton() calls for handlers that implement Default.
103//
104// Usage inside register():
105//   .register(|svc| {
106//       register_handlers!(svc,
107//           HelloRequest => String => HelloHandler,
108//           DeleteUserRequest => () => DeleteUserHandler,
109//       )
110//   })
111//
112// Expands to:
113//   svc
114//     .singleton::<dyn IRequestHandler<HelloRequest, String>>(|_| Arc::new(HelloHandler::default()))
115//     .singleton::<dyn IRequestHandler<DeleteUserRequest, ()>>(|_| Arc::new(DeleteUserHandler::default()))
116// =========================================================================
117#[macro_export]
118macro_rules! register_handlers {
119    ($svc:ident, $($req:ty => $rsp:ty => $handler:ty),+ $(,)?) => {
120        $svc
121        $(
122            .singleton::<dyn $crate::IRequestHandler<$req, $rsp>>(
123                |_| ::std::sync::Arc::new(<$handler>::default())
124            )
125        )+
126    };
127}