rustapi_core/
lib.rs

1//! # RustAPI Core
2//!
3//! Core library providing the foundational types and traits for RustAPI.
4//!
5//! This crate provides the essential building blocks for the RustAPI web framework:
6//!
7//! - **Application Builder**: [`RustApi`] - The main entry point for building web applications
8//! - **Routing**: [`Router`], [`get`], [`post`], [`put`], [`patch`], [`delete`] - HTTP routing primitives
9//! - **Extractors**: [`Json`], [`Query`], [`Path`], [`State`], [`Body`], [`Headers`] - Request data extraction
10//! - **Responses**: [`IntoResponse`], [`Created`], [`NoContent`], [`Html`], [`Redirect`] - Response types
11//! - **Middleware**: [`BodyLimitLayer`], [`RequestIdLayer`], [`TracingLayer`] - Request processing layers
12//! - **Error Handling**: [`ApiError`], [`Result`] - Structured error responses
13//! - **Testing**: `TestClient` - Integration testing without network binding (requires `test-utils` feature)
14//!
15//! ## Quick Start
16//!
17//! ```rust,ignore
18//! use rustapi_core::{RustApi, get, Json};
19//! use serde::Serialize;
20//!
21//! #[derive(Serialize)]
22//! struct Message {
23//!     text: String,
24//! }
25//!
26//! async fn hello() -> Json<Message> {
27//!     Json(Message { text: "Hello, World!".to_string() })
28//! }
29//!
30//! #[tokio::main]
31//! async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
32//!     RustApi::new()
33//!         .route("/", get(hello))
34//!         .run("127.0.0.1:8080")
35//!         .await
36//! }
37//! ```
38//!
39//! ## Feature Flags
40//!
41//! - `metrics` - Enable Prometheus metrics middleware
42//! - `cookies` - Enable cookie parsing extractor
43//! - `test-utils` - Enable testing utilities like `TestClient`
44//! - `swagger-ui` - Enable Swagger UI documentation endpoint
45//!
46//! ## Note
47//!
48//! This crate is typically not used directly. Use `rustapi-rs` instead for the
49//! full framework experience with all features and re-exports.
50
51mod app;
52pub mod auto_route;
53pub use auto_route::collect_auto_routes;
54pub mod auto_schema;
55pub use auto_schema::apply_auto_schemas;
56mod error;
57mod extract;
58mod handler;
59pub mod health;
60pub mod interceptor;
61pub mod json;
62pub mod middleware;
63pub mod multipart;
64pub mod path_params;
65pub mod path_validation;
66mod request;
67mod response;
68mod router;
69mod server;
70pub mod sse;
71pub mod static_files;
72pub mod stream;
73#[macro_use]
74mod tracing_macros;
75#[cfg(any(test, feature = "test-utils"))]
76mod test_client;
77
78/// Private module for macro internals - DO NOT USE DIRECTLY
79///
80/// This module is used by procedural macros to register routes.
81/// It is not part of the public API and may change at any time.
82#[doc(hidden)]
83pub mod __private {
84    pub use crate::auto_route::AUTO_ROUTES;
85    pub use crate::auto_schema::AUTO_SCHEMAS;
86    pub use linkme;
87    pub use rustapi_openapi;
88}
89
90// Public API
91pub use app::{RustApi, RustApiConfig};
92pub use error::{get_environment, ApiError, Environment, FieldError, Result};
93#[cfg(feature = "cookies")]
94pub use extract::Cookies;
95pub use extract::{
96    Body, BodyStream, ClientIp, Extension, FromRequest, FromRequestParts, HeaderValue, Headers,
97    Json, Path, Query, State, ValidatedJson,
98};
99pub use handler::{
100    delete_route, get_route, patch_route, post_route, put_route, Handler, HandlerService, Route,
101    RouteHandler,
102};
103pub use health::{HealthCheck, HealthCheckBuilder, HealthCheckResult, HealthStatus};
104pub use interceptor::{InterceptorChain, RequestInterceptor, ResponseInterceptor};
105#[cfg(feature = "compression")]
106pub use middleware::CompressionLayer;
107pub use middleware::{BodyLimitLayer, RequestId, RequestIdLayer, TracingLayer, DEFAULT_BODY_LIMIT};
108#[cfg(feature = "metrics")]
109pub use middleware::{MetricsLayer, MetricsResponse};
110pub use multipart::{Multipart, MultipartConfig, MultipartField, UploadedFile};
111pub use request::Request;
112pub use response::{Created, Html, IntoResponse, NoContent, Redirect, Response, WithStatus};
113pub use router::{delete, get, patch, post, put, MethodRouter, Router};
114pub use sse::{sse_response, KeepAlive, Sse, SseEvent};
115pub use static_files::{serve_dir, StaticFile, StaticFileConfig};
116pub use stream::{StreamBody, StreamingBody, StreamingConfig};
117#[cfg(any(test, feature = "test-utils"))]
118pub use test_client::{TestClient, TestRequest, TestResponse};