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