Skip to main content

rustapi_rs/
lib.rs

1//! # RustAPI
2//!
3//! Public facade crate for RustAPI.
4
5extern crate self as rustapi_rs;
6
7// Re-export all procedural macros from rustapi-macros.
8pub use rustapi_macros::*;
9
10/// Macro/runtime internals. Not part of the public compatibility contract.
11///
12/// This module is only for use by `rustapi-macros` and internal implementation.
13/// It re-exports `linkme` (used for automatic route & schema registration via
14/// distributed slices) and the raw slices.
15///
16/// External users should never name anything inside `__private`.
17#[doc(hidden)]
18pub mod __private {
19    pub use async_trait;
20    pub use rustapi_core as core;
21
22    /// Re-export of `linkme` for our proc-macro generated attributes.
23    /// See `rustapi_core::__private::linkme` for more details.
24    pub use rustapi_core::__private::linkme;
25
26    pub use rustapi_core::__private::{AUTO_ROUTES, AUTO_SCHEMAS};
27    pub use rustapi_openapi as openapi;
28    pub use rustapi_validate as validate;
29    pub use serde_json;
30}
31
32/// Stable core surface exposed by the facade.
33pub mod core {
34    pub use rustapi_core::validation::Validatable;
35    pub use rustapi_core::EventBus;
36    pub use rustapi_core::{auto_route_count, collect_auto_routes};
37    pub use rustapi_core::{
38        delete, delete_route, get, get_route, patch, patch_route, post, post_route, put, put_route,
39        route, serve_dir, sse_from_iter, sse_response, ApiError, AsyncValidatedJson, Body,
40        BodyLimitLayer, BodyStream, BodyVariant, ClientIp, Created, CursorPaginate,
41        CursorPaginated, Environment, Extension, FieldError, FromRequest, FromRequestParts,
42        Handler, HandlerService, HeaderValue, Headers, HealthCheck, HealthCheckBuilder,
43        HealthCheckResult, HealthEndpointConfig, HealthStatus, Html, IntoResponse, Json, KeepAlive,
44        MethodRouter, Multipart, MultipartConfig, MultipartField, NoContent, Paginate, Paginated,
45        Path, ProductionDefaultsConfig, Query, Redirect, Request, RequestDispatcher, RequestId,
46        RequestIdLayer, Response, ResponseBody, Result, Route, RouteHandler, RouteMatch, Router,
47        RustApi, RustApiConfig, Sse, SseEvent, State, StaticFile, StaticFileConfig, StatusCode,
48        StreamBody, StreamingMultipart, StreamingMultipartField, TracingLayer, Typed, TypedPath,
49        UploadedFile, ValidatedJson, WithStatus,
50    };
51
52    pub use rustapi_core::get_environment;
53
54    #[cfg(any(feature = "core-cookies", feature = "cookies"))]
55    pub use rustapi_core::Cookies;
56
57    #[cfg(any(feature = "core-compression", feature = "compression"))]
58    pub use rustapi_core::CompressionLayer;
59
60    #[cfg(any(feature = "core-compression", feature = "compression"))]
61    pub use rustapi_core::middleware::{CompressionAlgorithm, CompressionConfig};
62
63    #[cfg(any(feature = "core-http3", feature = "protocol-http3", feature = "http3"))]
64    pub use rustapi_core::{Http3Config, Http3Server};
65}
66
67// Backward-compatible root re-exports.
68pub use core::*;
69
70/// Optional protocol integrations grouped under a stable namespace.
71pub mod protocol {
72    #[cfg(any(feature = "protocol-toon", feature = "toon"))]
73    pub mod toon {
74        pub use rustapi_toon::*;
75    }
76
77    #[cfg(any(feature = "protocol-ws", feature = "ws"))]
78    pub mod ws {
79        pub use rustapi_ws::*;
80    }
81
82    #[cfg(any(feature = "protocol-view", feature = "view"))]
83    pub mod view {
84        pub use rustapi_view::*;
85    }
86
87    #[cfg(any(feature = "protocol-grpc", feature = "grpc"))]
88    pub mod grpc {
89        pub use rustapi_grpc::*;
90    }
91
92    #[cfg(any(feature = "protocol-mcp", feature = "mcp"))]
93    pub mod mcp {
94        pub use rustapi_mcp::*;
95    }
96
97    #[cfg(any(feature = "core-http3", feature = "protocol-http3", feature = "http3"))]
98    pub mod http3 {
99        pub use rustapi_core::{Http3Config, Http3Server};
100    }
101}
102
103/// Optional extras grouped under a stable namespace.
104pub mod extras {
105    #[cfg(any(feature = "extras-jwt", feature = "jwt"))]
106    pub mod jwt {
107        pub use rustapi_extras::jwt;
108        pub use rustapi_extras::{
109            create_token, AuthUser, JwtError, JwtLayer, JwtValidation, ValidatedClaims,
110        };
111    }
112
113    #[cfg(any(feature = "extras-cors", feature = "cors"))]
114    pub mod cors {
115        pub use rustapi_extras::cors;
116        pub use rustapi_extras::{AllowedOrigins, CorsLayer};
117    }
118
119    #[cfg(any(feature = "extras-rate-limit", feature = "rate-limit"))]
120    pub mod rate_limit {
121        pub use rustapi_extras::rate_limit;
122        pub use rustapi_extras::{RateLimitLayer, RateLimitStrategy};
123    }
124
125    #[cfg(any(feature = "extras-config", feature = "config"))]
126    pub mod config {
127        pub use rustapi_extras::config;
128        pub use rustapi_extras::{
129            env_or, env_parse, load_dotenv, load_dotenv_from, require_env, Config, ConfigError,
130            Environment,
131        };
132    }
133
134    #[cfg(any(feature = "extras-sqlx", feature = "sqlx"))]
135    pub mod sqlx {
136        pub use rustapi_extras::{convert_sqlx_error, SqlxErrorExt};
137    }
138
139    #[cfg(any(feature = "extras-insight", feature = "insight"))]
140    pub mod insight {
141        pub use rustapi_extras::insight;
142    }
143
144    #[cfg(any(feature = "extras-timeout", feature = "timeout"))]
145    pub mod timeout {
146        pub use rustapi_extras::timeout;
147    }
148
149    #[cfg(any(feature = "extras-guard", feature = "guard"))]
150    pub mod guard {
151        pub use rustapi_extras::guard;
152    }
153
154    #[cfg(any(feature = "extras-logging", feature = "logging"))]
155    pub mod logging {
156        pub use rustapi_extras::logging;
157    }
158
159    #[cfg(any(feature = "extras-circuit-breaker", feature = "circuit-breaker"))]
160    pub mod circuit_breaker {
161        pub use rustapi_extras::circuit_breaker;
162    }
163
164    #[cfg(any(feature = "extras-retry", feature = "retry"))]
165    pub mod retry {
166        pub use rustapi_extras::retry;
167    }
168
169    #[cfg(any(feature = "extras-security-headers", feature = "security-headers"))]
170    pub mod security_headers {
171        pub use rustapi_extras::security_headers;
172    }
173
174    #[cfg(any(feature = "extras-api-key", feature = "api-key"))]
175    pub mod api_key {
176        pub use rustapi_extras::api_key;
177    }
178
179    #[cfg(any(feature = "extras-cache", feature = "cache"))]
180    pub mod cache {
181        pub use rustapi_extras::cache;
182    }
183
184    #[cfg(any(feature = "extras-dedup", feature = "dedup"))]
185    pub mod dedup {
186        pub use rustapi_extras::dedup;
187    }
188
189    #[cfg(any(feature = "extras-sanitization", feature = "sanitization"))]
190    pub mod sanitization {
191        pub use rustapi_extras::sanitization;
192    }
193
194    #[cfg(any(feature = "extras-otel", feature = "otel"))]
195    pub mod otel {
196        pub use rustapi_extras::otel;
197    }
198
199    #[cfg(any(feature = "extras-structured-logging", feature = "structured-logging"))]
200    pub mod structured_logging {
201        pub use rustapi_extras::structured_logging;
202    }
203
204    #[cfg(any(feature = "extras-replay", feature = "replay"))]
205    pub mod replay {
206        pub use rustapi_core::replay::{
207            RecordedRequest, RecordedResponse, ReplayConfig, ReplayEntry, ReplayId, ReplayMeta,
208            ReplayQuery, ReplayStore, ReplayStoreError, ReplayStoreResult,
209        };
210        pub use rustapi_extras::replay;
211        pub use rustapi_extras::replay::{
212            FsReplayStore, FsReplayStoreConfig, InMemoryReplayStore, ReplayAdminAuth, ReplayClient,
213            ReplayClientError, ReplayLayer, RetentionJob,
214        };
215    }
216
217    #[cfg(any(feature = "extras-oauth2-client", feature = "oauth2-client"))]
218    pub mod oauth2 {
219        pub use rustapi_extras::oauth2;
220        pub use rustapi_extras::{
221            AuthorizationRequest, CsrfState, OAuth2Client, OAuth2Config, PkceVerifier, Provider,
222            TokenError, TokenResponse,
223        };
224    }
225
226    #[cfg(any(feature = "extras-session", feature = "session"))]
227    pub mod session {
228        pub use rustapi_extras::session;
229        pub use rustapi_extras::{
230            MemorySessionStore, Session, SessionConfig, SessionError, SessionLayer, SessionRecord,
231            SessionStore,
232        };
233
234        #[cfg(any(feature = "extras-session-redis", feature = "session-redis"))]
235        pub use rustapi_extras::RedisSessionStore;
236    }
237
238    #[cfg(any(feature = "extras-jobs", feature = "jobs"))]
239    pub mod jobs {
240        pub use rustapi_extras::jobs::{
241            EnqueueOptions, InMemoryBackend, Job, JobBackend, JobContext, JobError, JobQueue,
242            JobRequest,
243        };
244    }
245}
246
247/// Dashboard module: embedded isometric system dashboard.
248#[cfg(feature = "core-dashboard")]
249pub mod dashboard {
250    pub use rustapi_core::dashboard::{
251        DashboardConfig, DashboardHealthEndpointSnapshot, DashboardHealthSummary,
252        DashboardLiveCountersSnapshot, DashboardMetrics, DashboardReplayIndexSnapshot,
253        DashboardSnapshot, DashboardStageSnapshot, ExecutionPath, RequestStage, RouteGraphSnapshot,
254        RouteGroupSnapshot, RouteInventoryItem, RouteMetricsSnapshot,
255    };
256}
257
258// Root-level re-exports for dashboard types (convenience)
259#[cfg(feature = "core-dashboard")]
260pub use rustapi_core::dashboard::{DashboardConfig, DashboardMetrics, DashboardSnapshot};
261#[cfg(any(feature = "protocol-ws", feature = "ws"))]
262#[deprecated(note = "Use rustapi_rs::protocol::ws instead")]
263pub mod ws {
264    pub use crate::protocol::ws::*;
265}
266
267#[cfg(any(feature = "protocol-view", feature = "view"))]
268#[deprecated(note = "Use rustapi_rs::protocol::view instead")]
269pub mod view {
270    pub use crate::protocol::view::*;
271}
272
273#[cfg(any(feature = "protocol-grpc", feature = "grpc"))]
274#[deprecated(note = "Use rustapi_rs::protocol::grpc instead")]
275pub mod grpc {
276    pub use crate::protocol::grpc::*;
277}
278
279// Legacy root extras re-exports for compatibility.
280#[cfg(any(feature = "extras-jwt", feature = "jwt"))]
281pub use rustapi_extras::jwt;
282#[cfg(any(feature = "extras-jwt", feature = "jwt"))]
283pub use rustapi_extras::{
284    create_token, AuthUser, JwtError, JwtLayer, JwtValidation, ValidatedClaims,
285};
286
287#[cfg(any(feature = "extras-cors", feature = "cors"))]
288pub use rustapi_extras::cors;
289#[cfg(any(feature = "extras-cors", feature = "cors"))]
290pub use rustapi_extras::{AllowedOrigins, CorsLayer};
291
292#[cfg(any(feature = "extras-rate-limit", feature = "rate-limit"))]
293pub use rustapi_extras::rate_limit;
294#[cfg(any(feature = "extras-rate-limit", feature = "rate-limit"))]
295pub use rustapi_extras::{RateLimitLayer, RateLimitStrategy};
296
297#[cfg(any(feature = "extras-config", feature = "config"))]
298pub use rustapi_extras::config;
299#[cfg(any(feature = "extras-config", feature = "config"))]
300pub use rustapi_extras::{
301    env_or, env_parse, load_dotenv, load_dotenv_from, require_env, Config, ConfigError,
302    Environment as ExtrasEnvironment,
303};
304
305#[cfg(any(feature = "extras-sqlx", feature = "sqlx"))]
306pub use rustapi_extras::{convert_sqlx_error, SqlxErrorExt};
307
308#[cfg(any(feature = "extras-api-key", feature = "api-key"))]
309pub use rustapi_extras::api_key;
310#[cfg(any(feature = "extras-cache", feature = "cache"))]
311pub use rustapi_extras::cache;
312#[cfg(any(feature = "extras-circuit-breaker", feature = "circuit-breaker"))]
313pub use rustapi_extras::circuit_breaker;
314#[cfg(any(feature = "extras-dedup", feature = "dedup"))]
315pub use rustapi_extras::dedup;
316#[cfg(any(feature = "extras-guard", feature = "guard"))]
317pub use rustapi_extras::guard;
318#[cfg(any(feature = "extras-logging", feature = "logging"))]
319pub use rustapi_extras::logging;
320#[cfg(any(feature = "extras-otel", feature = "otel"))]
321pub use rustapi_extras::otel;
322#[cfg(any(feature = "extras-replay", feature = "replay"))]
323pub use rustapi_extras::replay;
324#[cfg(any(feature = "extras-retry", feature = "retry"))]
325pub use rustapi_extras::retry;
326#[cfg(any(feature = "extras-sanitization", feature = "sanitization"))]
327pub use rustapi_extras::sanitization;
328#[cfg(any(feature = "extras-security-headers", feature = "security-headers"))]
329pub use rustapi_extras::security_headers;
330#[cfg(any(feature = "extras-structured-logging", feature = "structured-logging"))]
331pub use rustapi_extras::structured_logging;
332#[cfg(any(feature = "extras-timeout", feature = "timeout"))]
333pub use rustapi_extras::timeout;
334
335#[cfg(any(feature = "extras-oauth2-client", feature = "oauth2-client"))]
336pub use rustapi_extras::oauth2;
337#[cfg(any(feature = "extras-oauth2-client", feature = "oauth2-client"))]
338pub use rustapi_extras::{
339    AuthorizationRequest, CsrfState, OAuth2Client, OAuth2Config, PkceVerifier, Provider,
340    TokenError, TokenResponse,
341};
342
343#[cfg(any(feature = "extras-session", feature = "session"))]
344pub use rustapi_extras::session;
345#[cfg(any(feature = "extras-session", feature = "session"))]
346pub use rustapi_extras::{
347    MemorySessionStore, Session, SessionConfig, SessionError, SessionLayer, SessionRecord,
348    SessionStore,
349};
350
351#[cfg(any(feature = "extras-session-redis", feature = "session-redis"))]
352pub use rustapi_extras::RedisSessionStore;
353
354#[cfg(any(feature = "extras-jobs", feature = "jobs"))]
355pub use rustapi_extras::jobs::{
356    EnqueueOptions, InMemoryBackend, Job, JobBackend, JobContext, JobError, JobQueue, JobRequest,
357};
358
359/// Prelude module: `use rustapi_rs::prelude::*`.
360pub mod prelude {
361    pub use crate::core::EventBus;
362    pub use crate::core::Validatable;
363    pub use crate::core::{
364        auto_route_count, collect_auto_routes, delete, delete_route, get, get_route, patch,
365        patch_route, post, post_route, put, put_route, route, serve_dir, sse_from_iter,
366        sse_response, ApiError, AsyncValidatedJson, Body, BodyLimitLayer, ClientIp, Created,
367        CursorPaginate, CursorPaginated, Extension, HeaderValue, Headers, HealthCheck,
368        HealthCheckBuilder, HealthCheckResult, HealthEndpointConfig, HealthStatus, Html,
369        IntoResponse, Json, KeepAlive, Multipart, MultipartConfig, MultipartField, NoContent,
370        Paginate, Paginated, Path, ProductionDefaultsConfig, Query, Redirect, Request,
371        RequestDispatcher, RequestId, RequestIdLayer, Response, Result, Route, Router, RustApi,
372        RustApiConfig, Sse, SseEvent, State, StaticFile, StaticFileConfig, StatusCode, StreamBody,
373        StreamingMultipart, StreamingMultipartField, TracingLayer, Typed, TypedPath, UploadedFile,
374        ValidatedJson, WithStatus,
375    };
376
377    #[cfg(any(feature = "core-compression", feature = "compression"))]
378    pub use crate::core::{CompressionAlgorithm, CompressionConfig, CompressionLayer};
379
380    #[cfg(any(feature = "core-cookies", feature = "cookies"))]
381    pub use crate::core::Cookies;
382
383    #[cfg(feature = "core-dashboard")]
384    pub use crate::{DashboardConfig, DashboardMetrics, DashboardSnapshot};
385
386    pub use rustapi_macros::ApiError;
387    pub use rustapi_macros::Schema;
388    pub use rustapi_macros::TypedPath;
389
390    pub use rustapi_validate::v2::AsyncValidate;
391    pub use rustapi_validate::v2::Validate as V2Validate;
392
393    #[cfg(any(feature = "core-legacy-validator", feature = "legacy-validator"))]
394    pub use validator::Validate;
395
396    pub use serde::{Deserialize, Serialize};
397    pub use tracing::{debug, error, info, trace, warn};
398
399    #[cfg(any(feature = "extras-jwt", feature = "jwt"))]
400    pub use crate::{create_token, AuthUser, JwtError, JwtLayer, JwtValidation, ValidatedClaims};
401
402    #[cfg(any(feature = "extras-cors", feature = "cors"))]
403    pub use crate::{AllowedOrigins, CorsLayer};
404
405    #[cfg(any(feature = "extras-rate-limit", feature = "rate-limit"))]
406    pub use crate::{RateLimitLayer, RateLimitStrategy};
407
408    #[cfg(any(feature = "extras-config", feature = "config"))]
409    pub use crate::{
410        env_or, env_parse, load_dotenv, load_dotenv_from, require_env, Config, ConfigError,
411        ExtrasEnvironment,
412    };
413
414    #[cfg(any(feature = "extras-sqlx", feature = "sqlx"))]
415    pub use crate::{convert_sqlx_error, SqlxErrorExt};
416
417    #[cfg(any(feature = "extras-oauth2-client", feature = "oauth2-client"))]
418    pub use crate::{
419        AuthorizationRequest, CsrfState, OAuth2Client, OAuth2Config, PkceVerifier, Provider,
420        TokenError, TokenResponse,
421    };
422
423    #[cfg(any(feature = "extras-session", feature = "session"))]
424    pub use crate::{
425        MemorySessionStore, Session, SessionConfig, SessionError, SessionLayer, SessionRecord,
426        SessionStore,
427    };
428
429    #[cfg(any(feature = "extras-session-redis", feature = "session-redis"))]
430    pub use crate::RedisSessionStore;
431
432    #[cfg(any(feature = "extras-jobs", feature = "jobs"))]
433    pub use crate::{
434        EnqueueOptions, InMemoryBackend, Job, JobBackend, JobContext, JobError, JobQueue,
435        JobRequest,
436    };
437
438    #[cfg(any(feature = "protocol-toon", feature = "toon"))]
439    pub use crate::protocol::toon::{AcceptHeader, LlmResponse, Negotiate, OutputFormat, Toon};
440
441    #[cfg(any(feature = "protocol-ws", feature = "ws"))]
442    pub use crate::protocol::ws::{Broadcast, Message, WebSocket, WebSocketStream};
443
444    #[cfg(any(feature = "protocol-view", feature = "view"))]
445    pub use crate::protocol::view::{ContextBuilder, Templates, TemplatesConfig, View};
446
447    #[cfg(any(feature = "protocol-grpc", feature = "grpc"))]
448    pub use crate::protocol::grpc::{
449        run_concurrently, run_rustapi_and_grpc, run_rustapi_and_grpc_with_shutdown,
450    };
451
452    #[cfg(any(feature = "protocol-mcp", feature = "mcp"))]
453    pub use crate::protocol::mcp::{run_rustapi_and_mcp, run_rustapi_and_mcp_with_shutdown};
454}
455
456#[cfg(test)]
457mod tests {
458    use super::prelude::*;
459
460    #[test]
461    fn prelude_imports_work() {
462        let _: fn() -> Result<()> = || Ok(());
463    }
464}