Skip to main content

webx/
lib.rs

1//! Umbrella crate for the rust-webx framework (package `rust-webx`, imported as
2//! `webx`).
3//!
4//! Re-exports the whole framework so applications need a single dependency:
5//!
6//! ```toml
7//! [dependencies]
8//! rust-webx = "1.1"
9//! ```
10//!
11//! ```ignore
12//! use webx::*;
13//! ```
14//!
15//! The dependency name is `rust-webx`; the import name is `webx`. The same
16//! applies to the sub-crates (`rust-webx-core` → `webx_core`,
17//! `rust-webx-host` → `webx_host`, `rust-webx-macros` → `webx_macros`,
18//! `rust-webx-spa` → `webx_spa`, `rust-webx-openapi` → `webx_openapi`).
19
20// --- Core traits ---
21pub use webx_core::action::{
22    ContentResult, FileResult, IActionResult, JsonResult, NoContentResult, Response,
23    StatusCodeResult,
24};
25pub use webx_core::app::IHost;
26pub use webx_core::auth::{
27    DeclaredRules, IAuthenticationHandler, IAuthorizationPolicy, IClaims, IDynamicAuthorizer,
28    IdentityUser, RequestUser,
29};
30pub use webx_core::cache::{
31    cache_ext::DistributedCacheExtensions,
32    options::DistributedCacheEntryOptions,
33    trait_def::{CacheError, IDistributedCache},
34};
35pub use webx_core::config::{
36    bind_config, bind_root, load_appsettings, AppOptions, AppSection, CorsSection, CultureSection,
37    IAppOptions, JwtSection, MetricsSection, RateLimitSection, TlsSection,
38};
39pub use webx_core::dispatch_runtime::DispatchRuntime;
40pub use webx_core::error::{ActionResult, Error, Result};
41pub use webx_core::form::{
42    sanitize_file_name, set_spool_root, spool_root, FormField, FormFile, FormFileBuilder,
43    MultipartForm, SPOOL_FILE_PREFIX,
44};
45pub use webx_core::handler::{IEventHandler, IHostedService, IRequestHandler};
46/// Background worker helpers: `BackgroundService`, `delay`, `CancellationToken`.
47pub use webx_core::hosted as background;
48pub use webx_core::hosted::{
49    BackgroundService, BackgroundServiceHost, CancellationToken, PeriodicBackgroundService,
50};
51pub use webx_core::http::{
52    content_disposition_value, read_json_body, write_json_response, ByteRange, Disposition,
53    FileBody, FileSource, HttpStatus, IClaimsExt, IHttpContext, IHttpRequest, IHttpResponse,
54    ResponseBody, SeekableReader, STREAM_BUF_SIZE,
55};
56pub use webx_core::localization::{
57    IStringLocalizer, LocalizationOptions, LocalizedString, StringLocalizer, TextRef,
58};
59pub use webx_core::mediator::dispatch;
60pub use webx_core::mediator::{IEventRequest, IMediator, IRequest};
61pub use webx_core::middleware::{IMiddleware, MiddlewareSlot};
62pub use webx_core::mode::AppMode;
63pub use webx_core::operation::OperationResult;
64pub use webx_core::pagination::{PagedRequest, PagedResult};
65pub use webx_core::paths::{
66    app_base, framework_root, looks_like_app_base, looks_like_framework_root,
67};
68pub use webx_core::pipeline::{IPipelineBehavior, Next};
69pub use webx_core::problem::{FieldError, ProblemDetails};
70pub use webx_core::request_context::RequestContext;
71pub use webx_core::route::catalog::{
72    EndpointCatalog, EndpointDescriptor, EndpointInfo, IEndpointCatalog,
73};
74pub use webx_core::route::diagnostics::{
75    duplicate_handlers, format_route_diagnostics, orphan_handlers, orphan_route_details,
76    orphan_routes, route_snapshots,
77};
78pub use webx_core::routing::{HttpMethod, IEndpoint, IRouter, RouteMeta};
79pub use webx_core::security::{
80    IPasswordHasher, ISessionStore, ITokenIssuer, InMemorySessionStore, IssuedToken, TokenClaims,
81};
82
83// --- DI extensions ---
84pub use webx_core::route::binding;
85pub use webx_core::route::binding::RequestModel;
86pub use webx_core::route::ext::{is_mediator_active, should_scan_endpoints, IServiceCollectionExt};
87pub use webx_core::route::scan::{
88    AuthorizeRule, BoxedDispatch, BoxedDispatchFn, BoxedDispatchFuture, HandlerCache, HandlerEntry,
89    HandlerRegistration, HandlerRegistry, ParamMeta, RequestParamEntry, RouteDispatch,
90    RouteDispatchFn, RouteEntry,
91};
92
93// --- HTTP layer ---
94pub use webx_host::auth_jwt::{
95    init_jwt_secret, jwt_middleware, jwt_middleware_with_revocation, jwt_secret, JwtAuth,
96    JwtClaims, JwtTokenIssuer, DEFAULT_TOKEN_LIFETIME,
97};
98pub use webx_host::authz::collect_authorizers;
99pub use webx_host::authz::resource_auth_middleware;
100pub use webx_host::authz::{AuthorizerSet, ResourceAuthorization};
101pub use webx_host::compression::{compress_gzip, CompressionConfig, CompressionMiddleware};
102pub use webx_host::context::{HttpContext, HttpRequest, HttpResponse};
103pub use webx_host::cors::{CorsConfig, CorsMiddleware};
104pub use webx_host::diagnostics::log_startup_diagnostics;
105pub use webx_host::endpoint::{
106    ControllerEndpoint, RequestEndpoint, StaticHtmlEndpoint, StaticJsonEndpoint,
107};
108pub use webx_host::health::{HealthCheckEntry, HealthCheckFn, HealthCheckRegistry, HealthStatus};
109pub use webx_host::memory_cache::MemoryCache;
110#[cfg(feature = "password-argon2")]
111pub use webx_host::password_argon2::{Argon2Params, Argon2PasswordHasher};
112pub use webx_host::pipeline::{HandlerFn, MiddlewarePipeline};
113pub use webx_host::rate_limit::{RateLimitMiddleware, RateLimiter};
114pub use webx_host::request_id::RequestIdMiddleware;
115pub use webx_host::request_tracing::RequestTracing;
116pub use webx_host::router::Router;
117pub use webx_host::security_headers::SecurityHeadersMiddleware;
118pub use webx_host::server::{Host, HostAppBuilder, HostBuilder, Server, ServerHandle};
119#[cfg(feature = "testing")]
120pub use webx_host::testing::{free_port, spawn, spawn_with_health, wait_until_ready, TestServer};
121pub use webx_host::timing::TimingMiddleware;
122
123// --- Mediator ---
124pub use webx_core::mediator::Mediator;
125
126// --- Web (SPA) ---
127pub use webx_spa::SpaMiddleware;
128
129/// Static file hosting, including files compiled into the executable.
130///
131/// ```ignore
132/// // build.rs: webx::builder().web_root("wwwroot").build()
133/// #[webx::main(embed)]
134/// async fn main() {
135///     Host::builder().use_spa("wwwroot").build()
136/// }
137/// ```
138pub mod spa {
139    pub use webx_spa::{
140        embed_assets, inventory, ContentEncoding, EmbeddedAsset, EmbeddedAssets, SpaMiddleware,
141        SpaSource, EMBED_ENV,
142    };
143}
144
145/// Files compiled into the executable by `#[webx::main(embed)]`, read by path.
146///
147/// ```ignore
148/// let config = webx::assets::read_str("config/default.json");
149/// ```
150pub mod assets {
151    pub use webx_spa::assets::{read, read_str};
152}
153
154// --- OpenAPI ---
155pub use webx_openapi::{generate_openapi_spec, APIUI_HTML};
156
157// --- Macros ---
158#[doc(hidden)]
159pub use webx_macros::{__webx_category, __webx_description, __webx_display};
160pub use webx_macros::{
161    authorize, category, delete, description, display, embed_assets, endpoint, get, handler, main,
162    post, put, WebxRequestMeta,
163};
164
165// --- Re-export rust_dix (for manual registration, #[inject] auto-registration, and module blocks) ---
166pub use rust_dix;
167pub use rust_dix::inject;
168pub use rust_dix::ScopeFactory;
169pub use rust_dix_macros;
170pub use rust_dix_macros::{module, Inject};
171
172// --- Re-export common dependencies ---
173pub use async_trait::async_trait;
174pub use hyper;
175/// Compile-time registration used by the derive macros.
176pub use inventory;
177pub use serde;
178pub use serde_json;
179pub use tokio;