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, framework_root, looks_like_app_base, looks_like_framework_root};
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    duplicate_handlers, format_route_diagnostics, orphan_handlers, orphan_route_details,
34    orphan_routes, route_snapshots,
35};
36pub use rust_webx_core::dispatch_runtime::{dispatch_provider, DispatchRuntime};
37pub use rust_webx_core::request_context::RequestContext;
38pub use rust_webx_core::routing::{HttpMethod, IEndpoint, IRouter, RouteMeta};
39
40// --- DI extensions ---
41pub use rust_webx_core::route::ext::{is_mediator_active, should_scan_endpoints, IServiceCollectionExt};
42pub use rust_webx_core::route::params::try_deserialize_from_params;
43#[allow(deprecated)]
44pub use rust_webx_core::route::scan::{
45    global_provider, set_global_provider, HandlerCache, HandlerEntry, HandlerRegistration,
46    HandlerRegistry, ParamMeta, RequestParamEntry, ResponseData, RouteDispatch, RouteEntry,
47};
48
49// --- HTTP layer ---
50pub use rust_webx_host::auth_jwt::{init_jwt_secret, jwt_middleware, jwt_secret, JwtAuth, JwtClaims};
51pub use rust_webx_host::authz::{
52    build_resource_policy_from_routes, collect_authorizers, resource_auth_middleware, AuthorizerSet,
53    ResourceAuthorization,
54};
55pub use rust_webx_host::compression::{compress_gzip, CompressionConfig, CompressionMiddleware};
56pub use rust_webx_host::context::{HttpContext, HttpRequest, HttpResponse};
57pub use rust_webx_host::cors::{CorsConfig, CorsMiddleware};
58pub use rust_webx_host::endpoint::{
59    ControllerEndpoint, RequestEndpoint, StaticHtmlEndpoint, StaticJsonEndpoint,
60};
61pub use rust_webx_host::health::{HealthCheckEntry, HealthCheckFn, HealthCheckRegistry, HealthStatus};
62pub use rust_webx_host::memory_cache::MemoryCache;
63pub use rust_webx_host::pipeline::{HandlerFn, MiddlewarePipeline};
64pub use rust_webx_host::rate_limit::{RateLimitMiddleware, RateLimiter};
65pub use rust_webx_host::request_id::RequestIdMiddleware;
66pub use rust_webx_host::request_tracing::RequestTracing;
67pub use rust_webx_host::router::Router;
68pub use rust_webx_host::security_headers::SecurityHeadersMiddleware;
69pub use rust_webx_host::diagnostics::log_startup_diagnostics;
70pub use rust_webx_host::server::{Host, HostAppBuilder, HostBuilder, Server, ServerHandle};
71pub use rust_webx_host::timing::TimingMiddleware;
72#[cfg(feature = "testing")]
73pub use rust_webx_host::testing::{free_port, spawn, spawn_with_health, wait_until_ready, TestServer};
74
75// --- Mediator ---
76pub use rust_webx_core::mediator::Mediator;
77
78// --- Web (SPA) ---
79pub use rust_webx_spa::SpaMiddleware;
80
81// --- OpenAPI ---
82pub use rust_webx_openapi::{generate_openapi_spec, APIUI_HTML};
83
84// --- Macros ---
85pub use rust_webx_macros::{
86    authorize, claims, delete, endpoint, get, handler, post, put, WebxRequestMeta,
87};
88
89// --- Re-export rust_dix (for manual registration, #[inject] auto-registration, and module blocks) ---
90pub use rust_dix;
91pub use rust_dix::inject;
92pub use rust_dix::ScopeFactory;
93pub use rust_dix_macros;
94pub use rust_dix_macros::{module, Inject};
95
96// --- Re-export common dependencies ---
97pub use async_trait::async_trait;
98pub use hyper;
99pub use serde;
100pub use serde_json;
101pub use tokio;
102
103// =========================================================================
104// Convenience macro: register_handlers!
105//
106// **Deprecated for HTTP handlers.** HTTP dispatch uses inventory +
107// `HandlerCache` exclusively (`#[handler]` / `#[handler(inject)]`).
108// Keep this macro only for non-HTTP Mediator use or manual DI registration.
109//
110// Generates chained .singleton() calls for handlers that implement Default.
111//
112// Usage inside register():
113//   .register(|svc| {
114//       register_handlers!(svc,
115//           HelloRequest => String => HelloHandler,
116//           DeleteUserRequest => () => DeleteUserHandler,
117//       )
118//   })
119// =========================================================================
120#[deprecated(
121    since = "0.2.0",
122    note = "HTTP handlers should use `#[handler]` / `#[handler(inject)]` (inventory). \
123            register_handlers! remains for non-HTTP Mediator scenarios only."
124)]
125#[macro_export]
126macro_rules! register_handlers {
127    ($svc:ident, $($req:ty => $rsp:ty => $handler:ty),+ $(,)?) => {
128        $svc
129        $(
130            .singleton::<dyn $crate::IRequestHandler<$req, $rsp>>(
131                |_| ::std::sync::Arc::new(<$handler>::default())
132            )
133        )+
134    };
135}