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.0"
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    IAuthenticationHandler, IAuthorizationPolicy, IClaims, IDynamicAuthorizer, IdentityUser,
28    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};
46pub use webx_core::http::{
47    content_disposition_value, read_json_body, write_json_response, ByteRange, Disposition,
48    FileBody, FileSource, HttpStatus, IClaimsExt, IHttpContext, IHttpRequest, IHttpResponse,
49    ResponseBody, SeekableReader, STREAM_BUF_SIZE,
50};
51pub use webx_core::localization::{
52    IStringLocalizer, LocalizationOptions, LocalizedString, StringLocalizer, TextRef,
53};
54pub use webx_core::mediator::dispatch;
55pub use webx_core::mediator::{IEventRequest, IMediator, IRequest};
56pub use webx_core::middleware::{IMiddleware, MiddlewareSlot};
57pub use webx_core::mode::AppMode;
58pub use webx_core::operation::OperationResult;
59pub use webx_core::pagination::{PagedRequest, PagedResult};
60pub use webx_core::paths::{
61    app_base, framework_root, looks_like_app_base, looks_like_framework_root,
62};
63pub use webx_core::pipeline::{IPipelineBehavior, Next};
64pub use webx_core::problem::{FieldError, ProblemDetails};
65pub use webx_core::request_context::RequestContext;
66pub use webx_core::route::catalog::{
67    EndpointCatalog, EndpointDescriptor, EndpointInfo, IEndpointCatalog,
68};
69pub use webx_core::route::diagnostics::{
70    duplicate_handlers, format_route_diagnostics, orphan_handlers, orphan_route_details,
71    orphan_routes, route_snapshots,
72};
73pub use webx_core::routing::{HttpMethod, IEndpoint, IRouter, RouteMeta};
74
75// --- DI extensions ---
76pub use webx_core::route::binding;
77pub use webx_core::route::binding::RequestModel;
78pub use webx_core::route::ext::{is_mediator_active, should_scan_endpoints, IServiceCollectionExt};
79pub use webx_core::route::scan::{
80    AuthorizeRule, BoxedDispatch, BoxedDispatchFn, BoxedDispatchFuture, HandlerCache, HandlerEntry,
81    HandlerRegistration, HandlerRegistry, ParamMeta, RequestParamEntry, RouteDispatch,
82    RouteDispatchFn, RouteEntry,
83};
84
85// --- HTTP layer ---
86pub use webx_host::auth_jwt::{init_jwt_secret, jwt_middleware, jwt_secret, JwtAuth, JwtClaims};
87pub use webx_host::authz::collect_authorizers;
88pub use webx_host::authz::resource_auth_middleware;
89pub use webx_host::authz::{AuthorizerSet, ResourceAuthorization};
90pub use webx_host::compression::{compress_gzip, CompressionConfig, CompressionMiddleware};
91pub use webx_host::context::{HttpContext, HttpRequest, HttpResponse};
92pub use webx_host::cors::{CorsConfig, CorsMiddleware};
93pub use webx_host::diagnostics::log_startup_diagnostics;
94pub use webx_host::endpoint::{
95    ControllerEndpoint, RequestEndpoint, StaticHtmlEndpoint, StaticJsonEndpoint,
96};
97pub use webx_host::health::{HealthCheckEntry, HealthCheckFn, HealthCheckRegistry, HealthStatus};
98pub use webx_host::memory_cache::MemoryCache;
99pub use webx_host::pipeline::{HandlerFn, MiddlewarePipeline};
100pub use webx_host::rate_limit::{RateLimitMiddleware, RateLimiter};
101pub use webx_host::request_id::RequestIdMiddleware;
102pub use webx_host::request_tracing::RequestTracing;
103pub use webx_host::router::Router;
104pub use webx_host::security_headers::SecurityHeadersMiddleware;
105pub use webx_host::server::{Host, HostAppBuilder, HostBuilder, Server, ServerHandle};
106#[cfg(feature = "testing")]
107pub use webx_host::testing::{free_port, spawn, spawn_with_health, wait_until_ready, TestServer};
108pub use webx_host::timing::TimingMiddleware;
109
110// --- Mediator ---
111pub use webx_core::mediator::Mediator;
112
113// --- Web (SPA) ---
114pub use webx_spa::SpaMiddleware;
115
116/// Static file hosting, including files compiled into the executable.
117///
118/// ```ignore
119/// // build.rs: webx::builder().web_root("wwwroot").build()
120/// #[webx::main(embed)]
121/// async fn main() {
122///     Host::builder().use_spa("wwwroot").build()
123/// }
124/// ```
125pub mod spa {
126    pub use webx_spa::{
127        embed_assets, inventory, ContentEncoding, EmbeddedAsset, EmbeddedAssets, SpaMiddleware,
128        SpaSource, EMBED_ENV,
129    };
130}
131
132/// Files compiled into the executable by `#[webx::main(embed)]`, read by path.
133///
134/// ```ignore
135/// let config = webx::assets::read_str("config/default.json");
136/// ```
137pub mod assets {
138    pub use webx_spa::assets::{read, read_str};
139}
140
141// --- OpenAPI ---
142pub use webx_openapi::{generate_openapi_spec, APIUI_HTML};
143
144// --- Macros ---
145#[doc(hidden)]
146pub use webx_macros::{__webx_category, __webx_description, __webx_display};
147pub use webx_macros::{
148    authorize, category, delete, description, display, embed_assets, endpoint, get, handler, main,
149    post, put, WebxRequestMeta,
150};
151
152// --- Re-export rust_dix (for manual registration, #[inject] auto-registration, and module blocks) ---
153pub use rust_dix;
154pub use rust_dix::inject;
155pub use rust_dix::ScopeFactory;
156pub use rust_dix_macros;
157pub use rust_dix_macros::{module, Inject};
158
159// --- Re-export common dependencies ---
160pub use async_trait::async_trait;
161pub use hyper;
162/// Compile-time registration used by the derive macros.
163pub use inventory;
164pub use serde;
165pub use serde_json;
166pub use tokio;