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::dispatch_runtime::{dispatch_provider, DispatchRuntime};
19pub use rust_webx_core::error::{Error, Result};
20pub use rust_webx_core::form::{
21    sanitize_file_name, set_spool_root, spool_root, FormDeserializer, FormError, FormField,
22    FormFile, FormFileBuilder, MultipartForm, SPOOL_FILE_PREFIX,
23};
24pub use rust_webx_core::handler::{IClaimsCarrier, IEventHandler, IHostedService, IRequestHandler};
25pub use rust_webx_core::http::{
26    content_disposition_value, read_json_body, write_json_response, ByteRange, Disposition,
27    FileBody, FileSource, FromHttpContext, HttpStatus, IClaimsExt, IHttpContext, IHttpRequest,
28    IHttpResponse, Json, ResponseBody, SeekableReader, STREAM_BUF_SIZE,
29};
30pub use rust_webx_core::mediator::build_pipeline_chain;
31pub use rust_webx_core::mediator::{IEventRequest, IMediator, IRequest};
32pub use rust_webx_core::middleware::IMiddleware;
33pub use rust_webx_core::mode::AppMode;
34pub use rust_webx_core::pagination::{PagedRequest, PagedResponse};
35pub use rust_webx_core::paths::{
36    app_base, framework_root, looks_like_app_base, looks_like_framework_root,
37};
38pub use rust_webx_core::pipeline::{BoxedNextFn, BoxedPipelineFuture, IPipelineBehavior};
39pub use rust_webx_core::problem::{FieldError, ProblemDetails};
40pub use rust_webx_core::request_context::RequestContext;
41pub use rust_webx_core::route::diagnostics::{
42    duplicate_handlers, format_route_diagnostics, orphan_handlers, orphan_route_details,
43    orphan_routes, route_snapshots,
44};
45pub use rust_webx_core::routing::{HttpMethod, IEndpoint, IRouter, RouteMeta};
46
47// --- DI extensions ---
48pub use rust_webx_core::route::ext::{
49    is_mediator_active, should_scan_endpoints, IServiceCollectionExt,
50};
51pub use rust_webx_core::route::bind::bind_form_request;
52pub use rust_webx_core::route::params::try_deserialize_from_params;
53#[allow(deprecated)]
54pub use rust_webx_core::route::scan::{
55    global_provider, set_global_provider, HandlerCache, HandlerEntry, HandlerRegistration,
56    HandlerRegistry, ParamMeta, RequestParamEntry, ResponseData, RouteDispatch, RouteDispatchFn,
57    RouteEntry,
58};
59
60// --- HTTP layer ---
61pub use rust_webx_host::auth_jwt::{
62    init_jwt_secret, jwt_middleware, jwt_secret, JwtAuth, JwtClaims,
63};
64pub use rust_webx_host::authz::{
65    build_resource_policy_from_routes, collect_authorizers, resource_auth_middleware,
66    AuthorizerSet, ResourceAuthorization,
67};
68pub use rust_webx_host::compression::{compress_gzip, CompressionConfig, CompressionMiddleware};
69pub use rust_webx_host::context::{HttpContext, HttpRequest, HttpResponse};
70pub use rust_webx_host::cors::{CorsConfig, CorsMiddleware};
71pub use rust_webx_host::diagnostics::log_startup_diagnostics;
72pub use rust_webx_host::endpoint::{
73    ControllerEndpoint, RequestEndpoint, StaticHtmlEndpoint, StaticJsonEndpoint,
74};
75pub use rust_webx_host::health::{
76    HealthCheckEntry, HealthCheckFn, HealthCheckRegistry, HealthStatus,
77};
78pub use rust_webx_host::memory_cache::MemoryCache;
79pub use rust_webx_host::pipeline::{HandlerFn, MiddlewarePipeline};
80pub use rust_webx_host::rate_limit::{RateLimitMiddleware, RateLimiter};
81pub use rust_webx_host::request_id::RequestIdMiddleware;
82pub use rust_webx_host::request_tracing::RequestTracing;
83pub use rust_webx_host::router::Router;
84pub use rust_webx_host::security_headers::SecurityHeadersMiddleware;
85pub use rust_webx_host::server::{Host, HostAppBuilder, HostBuilder, Server, ServerHandle};
86#[cfg(feature = "testing")]
87pub use rust_webx_host::testing::{
88    free_port, spawn, spawn_with_health, wait_until_ready, TestServer,
89};
90pub use rust_webx_host::timing::TimingMiddleware;
91
92// --- Mediator ---
93pub use rust_webx_core::mediator::Mediator;
94
95// --- Web (SPA) ---
96pub use rust_webx_spa::SpaMiddleware;
97
98// --- OpenAPI ---
99pub use rust_webx_openapi::{generate_openapi_spec, APIUI_HTML};
100
101// --- Macros ---
102pub use rust_webx_macros::{
103    authorize, claims, delete, endpoint, get, handler, post, put, WebxRequestMeta,
104};
105
106// --- Re-export rust_dix (for manual registration, #[inject] auto-registration, and module blocks) ---
107pub use rust_dix;
108pub use rust_dix::inject;
109pub use rust_dix::ScopeFactory;
110pub use rust_dix_macros;
111pub use rust_dix_macros::{module, Inject};
112
113// --- Re-export common dependencies ---
114pub use async_trait::async_trait;
115pub use hyper;
116pub use serde;
117pub use serde_json;
118pub use tokio;
119
120// =========================================================================
121// Convenience macro: register_handlers!
122//
123// **Deprecated for HTTP handlers.** HTTP dispatch uses inventory +
124// `HandlerCache` exclusively (`#[handler]` / `#[handler(inject)]`).
125// Keep this macro only for non-HTTP Mediator use or manual DI registration.
126//
127// Generates chained .singleton() calls for handlers that implement Default.
128//
129// Usage inside register():
130//   .register(|svc| {
131//       register_handlers!(svc,
132//           HelloRequest => String => HelloHandler,
133//           DeleteUserRequest => () => DeleteUserHandler,
134//       )
135//   })
136// =========================================================================
137#[deprecated(
138    since = "0.2.0",
139    note = "HTTP handlers should use `#[handler]` / `#[handler(inject)]` (inventory). \
140            register_handlers! remains for non-HTTP Mediator scenarios only."
141)]
142#[macro_export]
143macro_rules! register_handlers {
144    ($svc:ident, $($req:ty => $rsp:ty => $handler:ty),+ $(,)?) => {
145        $svc
146        $(
147            .singleton::<dyn $crate::IRequestHandler<$req, $rsp>>(
148                |_| ::std::sync::Arc::new(<$handler>::default())
149            )
150        )+
151    };
152}