Skip to main content

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//! - `http3` - Enable HTTP/3 (QUIC) support
46//! - `http3-dev` - Enable HTTP/3 with self-signed certificate generation
47//!
48//! ## Note
49//!
50//! This crate is typically not used directly. Use `rustapi-rs` instead for the
51//! full framework experience with all features and re-exports.
52
53mod app;
54pub mod auto_route;
55pub use auto_route::collect_auto_routes;
56pub mod auto_schema;
57pub use auto_schema::apply_auto_schemas;
58mod error;
59mod extract;
60mod handler;
61pub mod hateoas;
62pub mod health;
63#[cfg(feature = "http3")]
64pub mod http3;
65pub mod interceptor;
66pub mod json;
67pub mod middleware;
68pub mod multipart;
69pub mod path_params;
70pub mod path_validation;
71#[cfg(feature = "replay")]
72pub mod replay;
73mod request;
74mod response;
75mod router;
76mod server;
77pub mod sse;
78pub mod static_files;
79pub mod status;
80pub mod stream;
81pub mod typed_path;
82pub mod validation;
83#[macro_use]
84mod tracing_macros;
85
86/// Private module for macro internals - DO NOT USE DIRECTLY
87///
88/// This module is used by procedural macros to register routes.
89/// It is not part of the public API and may change at any time.
90#[doc(hidden)]
91pub mod __private {
92    pub use crate::auto_route::AUTO_ROUTES;
93    pub use crate::auto_schema::AUTO_SCHEMAS;
94    pub use linkme;
95    pub use rustapi_openapi;
96}
97
98// Public API
99pub use app::{RustApi, RustApiConfig};
100pub use error::{get_environment, ApiError, Environment, FieldError, Result};
101#[cfg(feature = "cookies")]
102pub use extract::Cookies;
103pub use extract::{
104    AsyncValidatedJson, Body, BodyStream, ClientIp, Extension, FromRequest, FromRequestParts,
105    HeaderValue, Headers, Json, Path, Query, State, Typed, ValidatedJson,
106};
107pub use handler::{
108    delete_route, get_route, patch_route, post_route, put_route, Handler, HandlerService, Route,
109    RouteHandler,
110};
111pub use hateoas::{Link, LinkOrArray, Linkable, PageInfo, Resource, ResourceCollection};
112pub use health::{HealthCheck, HealthCheckBuilder, HealthCheckResult, HealthStatus};
113pub use http::StatusCode;
114#[cfg(feature = "http3")]
115pub use http3::{Http3Config, Http3Server};
116pub use interceptor::{InterceptorChain, RequestInterceptor, ResponseInterceptor};
117#[cfg(feature = "compression")]
118pub use middleware::CompressionLayer;
119pub use middleware::{BodyLimitLayer, RequestId, RequestIdLayer, TracingLayer, DEFAULT_BODY_LIMIT};
120#[cfg(feature = "metrics")]
121pub use middleware::{MetricsLayer, MetricsResponse};
122pub use multipart::{Multipart, MultipartConfig, MultipartField, UploadedFile};
123pub use request::{BodyVariant, Request};
124pub use response::{
125    Body as ResponseBody, Created, Html, IntoResponse, NoContent, Redirect, Response, WithStatus,
126};
127pub use router::{delete, get, patch, post, put, MethodRouter, RouteMatch, Router};
128pub use sse::{sse_response, KeepAlive, Sse, SseEvent};
129pub use static_files::{serve_dir, StaticFile, StaticFileConfig};
130pub use stream::{StreamBody, StreamingBody, StreamingConfig};
131pub use typed_path::TypedPath;
132pub use validation::Validatable;