rustapi-rs 0.1.450

A FastAPI-like web framework for Rust - DX-first, type-safe, batteries included
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
//! # RustAPI
//!
//! Public facade crate for RustAPI.

extern crate self as rustapi_rs;

// Re-export all procedural macros from rustapi-macros.
pub use rustapi_macros::*;

/// Macro/runtime internals. Not part of the public compatibility contract.
#[doc(hidden)]
pub mod __private {
    pub use async_trait;
    pub use rustapi_core as core;
    pub use rustapi_core::__private::{linkme, AUTO_ROUTES, AUTO_SCHEMAS};
    pub use rustapi_openapi as openapi;
    pub use rustapi_validate as validate;
    pub use serde_json;
}

/// Stable core surface exposed by the facade.
pub mod core {
    pub use rustapi_core::collect_auto_routes;
    pub use rustapi_core::validation::Validatable;
    pub use rustapi_core::EventBus;
    pub use rustapi_core::{
        delete, delete_route, get, get_route, patch, patch_route, post, post_route, put, put_route,
        route, serve_dir, sse_from_iter, sse_response, ApiError, AsyncValidatedJson, Body,
        BodyLimitLayer, BodyStream, BodyVariant, ClientIp, Created, CursorPaginate,
        CursorPaginated, Environment, Extension, FieldError, FromRequest, FromRequestParts,
        Handler, HandlerService, HeaderValue, Headers, HealthCheck, HealthCheckBuilder,
        HealthCheckResult, HealthEndpointConfig, HealthStatus, Html, IntoResponse, Json, KeepAlive,
        MethodRouter, Multipart, MultipartConfig, MultipartField, NoContent, Paginate, Paginated,
        Path, ProductionDefaultsConfig, Query, Redirect, Request, RequestId, RequestIdLayer,
        Response, ResponseBody, Result, Route, RouteHandler, RouteMatch, Router, RustApi,
        RustApiConfig, Sse, SseEvent, State, StaticFile, StaticFileConfig, StatusCode, StreamBody,
        StreamingMultipart, StreamingMultipartField, TracingLayer, Typed, TypedPath, UploadedFile,
        ValidatedJson, WithStatus,
    };

    pub use rustapi_core::get_environment;

    #[cfg(any(feature = "core-cookies", feature = "cookies"))]
    pub use rustapi_core::Cookies;

    #[cfg(any(feature = "core-compression", feature = "compression"))]
    pub use rustapi_core::CompressionLayer;

    #[cfg(any(feature = "core-compression", feature = "compression"))]
    pub use rustapi_core::middleware::{CompressionAlgorithm, CompressionConfig};

    #[cfg(any(feature = "core-http3", feature = "protocol-http3", feature = "http3"))]
    pub use rustapi_core::{Http3Config, Http3Server};
}

// Backward-compatible root re-exports.
pub use core::*;

/// Optional protocol integrations grouped under a stable namespace.
pub mod protocol {
    #[cfg(any(feature = "protocol-toon", feature = "toon"))]
    pub mod toon {
        pub use rustapi_toon::*;
    }

    #[cfg(any(feature = "protocol-ws", feature = "ws"))]
    pub mod ws {
        pub use rustapi_ws::*;
    }

    #[cfg(any(feature = "protocol-view", feature = "view"))]
    pub mod view {
        pub use rustapi_view::*;
    }

    #[cfg(any(feature = "protocol-grpc", feature = "grpc"))]
    pub mod grpc {
        pub use rustapi_grpc::*;
    }

    #[cfg(any(feature = "core-http3", feature = "protocol-http3", feature = "http3"))]
    pub mod http3 {
        pub use rustapi_core::{Http3Config, Http3Server};
    }
}

/// Optional extras grouped under a stable namespace.
pub mod extras {
    #[cfg(any(feature = "extras-jwt", feature = "jwt"))]
    pub mod jwt {
        pub use rustapi_extras::jwt;
        pub use rustapi_extras::{
            create_token, AuthUser, JwtError, JwtLayer, JwtValidation, ValidatedClaims,
        };
    }

    #[cfg(any(feature = "extras-cors", feature = "cors"))]
    pub mod cors {
        pub use rustapi_extras::cors;
        pub use rustapi_extras::{AllowedOrigins, CorsLayer};
    }

    #[cfg(any(feature = "extras-rate-limit", feature = "rate-limit"))]
    pub mod rate_limit {
        pub use rustapi_extras::rate_limit;
        pub use rustapi_extras::{RateLimitLayer, RateLimitStrategy};
    }

    #[cfg(any(feature = "extras-config", feature = "config"))]
    pub mod config {
        pub use rustapi_extras::config;
        pub use rustapi_extras::{
            env_or, env_parse, load_dotenv, load_dotenv_from, require_env, Config, ConfigError,
            Environment,
        };
    }

    #[cfg(any(feature = "extras-sqlx", feature = "sqlx"))]
    pub mod sqlx {
        pub use rustapi_extras::{convert_sqlx_error, SqlxErrorExt};
    }

    #[cfg(any(feature = "extras-insight", feature = "insight"))]
    pub mod insight {
        pub use rustapi_extras::insight;
    }

    #[cfg(any(feature = "extras-timeout", feature = "timeout"))]
    pub mod timeout {
        pub use rustapi_extras::timeout;
    }

    #[cfg(any(feature = "extras-guard", feature = "guard"))]
    pub mod guard {
        pub use rustapi_extras::guard;
    }

    #[cfg(any(feature = "extras-logging", feature = "logging"))]
    pub mod logging {
        pub use rustapi_extras::logging;
    }

    #[cfg(any(feature = "extras-circuit-breaker", feature = "circuit-breaker"))]
    pub mod circuit_breaker {
        pub use rustapi_extras::circuit_breaker;
    }

    #[cfg(any(feature = "extras-retry", feature = "retry"))]
    pub mod retry {
        pub use rustapi_extras::retry;
    }

    #[cfg(any(feature = "extras-security-headers", feature = "security-headers"))]
    pub mod security_headers {
        pub use rustapi_extras::security_headers;
    }

    #[cfg(any(feature = "extras-api-key", feature = "api-key"))]
    pub mod api_key {
        pub use rustapi_extras::api_key;
    }

    #[cfg(any(feature = "extras-cache", feature = "cache"))]
    pub mod cache {
        pub use rustapi_extras::cache;
    }

    #[cfg(any(feature = "extras-dedup", feature = "dedup"))]
    pub mod dedup {
        pub use rustapi_extras::dedup;
    }

    #[cfg(any(feature = "extras-sanitization", feature = "sanitization"))]
    pub mod sanitization {
        pub use rustapi_extras::sanitization;
    }

    #[cfg(any(feature = "extras-otel", feature = "otel"))]
    pub mod otel {
        pub use rustapi_extras::otel;
    }

    #[cfg(any(feature = "extras-structured-logging", feature = "structured-logging"))]
    pub mod structured_logging {
        pub use rustapi_extras::structured_logging;
    }

    #[cfg(any(feature = "extras-replay", feature = "replay"))]
    pub mod replay {
        pub use rustapi_core::replay::{
            RecordedRequest, RecordedResponse, ReplayConfig, ReplayEntry, ReplayId, ReplayMeta,
            ReplayQuery, ReplayStore, ReplayStoreError, ReplayStoreResult,
        };
        pub use rustapi_extras::replay;
        pub use rustapi_extras::replay::{
            FsReplayStore, FsReplayStoreConfig, InMemoryReplayStore, ReplayAdminAuth, ReplayClient,
            ReplayClientError, ReplayLayer, RetentionJob,
        };
    }

    #[cfg(any(feature = "extras-oauth2-client", feature = "oauth2-client"))]
    pub mod oauth2 {
        pub use rustapi_extras::oauth2;
        pub use rustapi_extras::{
            AuthorizationRequest, CsrfState, OAuth2Client, OAuth2Config, PkceVerifier, Provider,
            TokenError, TokenResponse,
        };
    }

    #[cfg(any(feature = "extras-session", feature = "session"))]
    pub mod session {
        pub use rustapi_extras::session;
        pub use rustapi_extras::{
            MemorySessionStore, Session, SessionConfig, SessionError, SessionLayer, SessionRecord,
            SessionStore,
        };

        #[cfg(any(feature = "extras-session-redis", feature = "session-redis"))]
        pub use rustapi_extras::RedisSessionStore;
    }

    #[cfg(any(feature = "extras-jobs", feature = "jobs"))]
    pub mod jobs {
        pub use rustapi_jobs::{
            EnqueueOptions, InMemoryBackend, Job, JobBackend, JobContext, JobError, JobQueue,
            JobRequest,
        };
    }
}

// Legacy root module aliases.
#[cfg(any(feature = "protocol-toon", feature = "toon"))]
#[deprecated(note = "Use rustapi_rs::protocol::toon instead")]
pub mod toon {
    pub use crate::protocol::toon::*;
}

#[cfg(any(feature = "protocol-ws", feature = "ws"))]
#[deprecated(note = "Use rustapi_rs::protocol::ws instead")]
pub mod ws {
    pub use crate::protocol::ws::*;
}

#[cfg(any(feature = "protocol-view", feature = "view"))]
#[deprecated(note = "Use rustapi_rs::protocol::view instead")]
pub mod view {
    pub use crate::protocol::view::*;
}

#[cfg(any(feature = "protocol-grpc", feature = "grpc"))]
#[deprecated(note = "Use rustapi_rs::protocol::grpc instead")]
pub mod grpc {
    pub use crate::protocol::grpc::*;
}

// Legacy root extras re-exports for compatibility.
#[cfg(any(feature = "extras-jwt", feature = "jwt"))]
pub use rustapi_extras::jwt;
#[cfg(any(feature = "extras-jwt", feature = "jwt"))]
pub use rustapi_extras::{
    create_token, AuthUser, JwtError, JwtLayer, JwtValidation, ValidatedClaims,
};

#[cfg(any(feature = "extras-cors", feature = "cors"))]
pub use rustapi_extras::cors;
#[cfg(any(feature = "extras-cors", feature = "cors"))]
pub use rustapi_extras::{AllowedOrigins, CorsLayer};

#[cfg(any(feature = "extras-rate-limit", feature = "rate-limit"))]
pub use rustapi_extras::rate_limit;
#[cfg(any(feature = "extras-rate-limit", feature = "rate-limit"))]
pub use rustapi_extras::{RateLimitLayer, RateLimitStrategy};

#[cfg(any(feature = "extras-config", feature = "config"))]
pub use rustapi_extras::config;
#[cfg(any(feature = "extras-config", feature = "config"))]
pub use rustapi_extras::{
    env_or, env_parse, load_dotenv, load_dotenv_from, require_env, Config, ConfigError,
    Environment as ExtrasEnvironment,
};

#[cfg(any(feature = "extras-sqlx", feature = "sqlx"))]
pub use rustapi_extras::{convert_sqlx_error, SqlxErrorExt};

#[cfg(any(feature = "extras-api-key", feature = "api-key"))]
pub use rustapi_extras::api_key;
#[cfg(any(feature = "extras-cache", feature = "cache"))]
pub use rustapi_extras::cache;
#[cfg(any(feature = "extras-circuit-breaker", feature = "circuit-breaker"))]
pub use rustapi_extras::circuit_breaker;
#[cfg(any(feature = "extras-dedup", feature = "dedup"))]
pub use rustapi_extras::dedup;
#[cfg(any(feature = "extras-guard", feature = "guard"))]
pub use rustapi_extras::guard;
#[cfg(any(feature = "extras-logging", feature = "logging"))]
pub use rustapi_extras::logging;
#[cfg(any(feature = "extras-otel", feature = "otel"))]
pub use rustapi_extras::otel;
#[cfg(any(feature = "extras-replay", feature = "replay"))]
pub use rustapi_extras::replay;
#[cfg(any(feature = "extras-retry", feature = "retry"))]
pub use rustapi_extras::retry;
#[cfg(any(feature = "extras-sanitization", feature = "sanitization"))]
pub use rustapi_extras::sanitization;
#[cfg(any(feature = "extras-security-headers", feature = "security-headers"))]
pub use rustapi_extras::security_headers;
#[cfg(any(feature = "extras-structured-logging", feature = "structured-logging"))]
pub use rustapi_extras::structured_logging;
#[cfg(any(feature = "extras-timeout", feature = "timeout"))]
pub use rustapi_extras::timeout;

#[cfg(any(feature = "extras-oauth2-client", feature = "oauth2-client"))]
pub use rustapi_extras::oauth2;
#[cfg(any(feature = "extras-oauth2-client", feature = "oauth2-client"))]
pub use rustapi_extras::{
    AuthorizationRequest, CsrfState, OAuth2Client, OAuth2Config, PkceVerifier, Provider,
    TokenError, TokenResponse,
};

#[cfg(any(feature = "extras-session", feature = "session"))]
pub use rustapi_extras::session;
#[cfg(any(feature = "extras-session", feature = "session"))]
pub use rustapi_extras::{
    MemorySessionStore, Session, SessionConfig, SessionError, SessionLayer, SessionRecord,
    SessionStore,
};

#[cfg(any(feature = "extras-session-redis", feature = "session-redis"))]
pub use rustapi_extras::RedisSessionStore;

#[cfg(any(feature = "extras-jobs", feature = "jobs"))]
pub use rustapi_jobs::{
    EnqueueOptions, InMemoryBackend, Job, JobBackend, JobContext, JobError, JobQueue, JobRequest,
};

/// Prelude module: `use rustapi_rs::prelude::*`.
pub mod prelude {
    pub use crate::core::EventBus;
    pub use crate::core::Validatable;
    pub use crate::core::{
        delete, delete_route, get, get_route, patch, patch_route, post, post_route, put, put_route,
        route, serve_dir, sse_from_iter, sse_response, ApiError, AsyncValidatedJson, Body,
        BodyLimitLayer, ClientIp, Created, CursorPaginate, CursorPaginated, Extension, HeaderValue,
        Headers, HealthCheck, HealthCheckBuilder, HealthCheckResult, HealthEndpointConfig,
        HealthStatus, Html, IntoResponse, Json, KeepAlive, Multipart, MultipartConfig,
        MultipartField, NoContent, Paginate, Paginated, Path, ProductionDefaultsConfig, Query,
        Redirect, Request, RequestId, RequestIdLayer, Response, Result, Route, Router, RustApi,
        RustApiConfig, Sse, SseEvent, State, StaticFile, StaticFileConfig, StatusCode, StreamBody,
        StreamingMultipart, StreamingMultipartField, TracingLayer, Typed, TypedPath, UploadedFile,
        ValidatedJson, WithStatus,
    };

    #[cfg(any(feature = "core-compression", feature = "compression"))]
    pub use crate::core::{CompressionAlgorithm, CompressionConfig, CompressionLayer};

    #[cfg(any(feature = "core-cookies", feature = "cookies"))]
    pub use crate::core::Cookies;

    pub use rustapi_macros::ApiError;
    pub use rustapi_macros::Schema;
    pub use rustapi_macros::TypedPath;

    pub use rustapi_validate::v2::AsyncValidate;
    pub use rustapi_validate::v2::Validate as V2Validate;

    #[cfg(any(feature = "core-legacy-validator", feature = "legacy-validator"))]
    pub use validator::Validate;

    pub use serde::{Deserialize, Serialize};
    pub use tracing::{debug, error, info, trace, warn};

    #[cfg(any(feature = "extras-jwt", feature = "jwt"))]
    pub use crate::{create_token, AuthUser, JwtError, JwtLayer, JwtValidation, ValidatedClaims};

    #[cfg(any(feature = "extras-cors", feature = "cors"))]
    pub use crate::{AllowedOrigins, CorsLayer};

    #[cfg(any(feature = "extras-rate-limit", feature = "rate-limit"))]
    pub use crate::{RateLimitLayer, RateLimitStrategy};

    #[cfg(any(feature = "extras-config", feature = "config"))]
    pub use crate::{
        env_or, env_parse, load_dotenv, load_dotenv_from, require_env, Config, ConfigError,
        ExtrasEnvironment,
    };

    #[cfg(any(feature = "extras-sqlx", feature = "sqlx"))]
    pub use crate::{convert_sqlx_error, SqlxErrorExt};

    #[cfg(any(feature = "extras-oauth2-client", feature = "oauth2-client"))]
    pub use crate::{
        AuthorizationRequest, CsrfState, OAuth2Client, OAuth2Config, PkceVerifier, Provider,
        TokenError, TokenResponse,
    };

    #[cfg(any(feature = "extras-session", feature = "session"))]
    pub use crate::{
        MemorySessionStore, Session, SessionConfig, SessionError, SessionLayer, SessionRecord,
        SessionStore,
    };

    #[cfg(any(feature = "extras-session-redis", feature = "session-redis"))]
    pub use crate::RedisSessionStore;

    #[cfg(any(feature = "extras-jobs", feature = "jobs"))]
    pub use crate::{
        EnqueueOptions, InMemoryBackend, Job, JobBackend, JobContext, JobError, JobQueue,
        JobRequest,
    };

    #[cfg(any(feature = "protocol-toon", feature = "toon"))]
    pub use crate::protocol::toon::{AcceptHeader, LlmResponse, Negotiate, OutputFormat, Toon};

    #[cfg(any(feature = "protocol-ws", feature = "ws"))]
    pub use crate::protocol::ws::{Broadcast, Message, WebSocket, WebSocketStream};

    #[cfg(any(feature = "protocol-view", feature = "view"))]
    pub use crate::protocol::view::{ContextBuilder, Templates, TemplatesConfig, View};

    #[cfg(any(feature = "protocol-grpc", feature = "grpc"))]
    pub use crate::protocol::grpc::{
        run_concurrently, run_rustapi_and_grpc, run_rustapi_and_grpc_with_shutdown,
    };
}

#[cfg(test)]
mod tests {
    use super::prelude::*;

    #[test]
    fn prelude_imports_work() {
        let _: fn() -> Result<()> = || Ok(());
    }
}