reinhardt_http/lib.rs
1//! HTTP request and response handling for Reinhardt framework.
2//!
3//! This crate provides core HTTP abstractions including request and response types,
4//! header handling, and content negotiation.
5//!
6//! ## Request Construction
7//!
8//! Requests are constructed using the builder pattern for type-safe configuration:
9//!
10//! ```rust
11//! use reinhardt_http::Request;
12//! use hyper::{Method, HeaderMap};
13//!
14//! let request = Request::builder()
15//! .method(Method::POST)
16//! .uri("/api/users")
17//! .version(hyper::Version::HTTP_11)
18//! .headers(HeaderMap::new())
19//! .body(bytes::Bytes::from("request body"))
20//! .build()
21//! .unwrap();
22//! ```
23//!
24//! ## Response Creation
25//!
26//! Responses use helper methods and builder pattern:
27//!
28//! ```rust
29//! use reinhardt_http::Response;
30//!
31//! // Using helpers
32//! let response = Response::ok().with_body("Hello, World!");
33//!
34//! // With JSON
35//! let json_response = Response::ok()
36//! .with_json(&serde_json::json!({"status": "success"}))
37//! .unwrap();
38//! ```
39
40pub mod auth_state;
41pub mod chunked_upload;
42pub mod extensions;
43#[cfg(feature = "messages")]
44pub mod messages_middleware;
45pub mod middleware;
46pub mod request;
47pub mod response;
48pub mod upload;
49
50pub use auth_state::AuthState;
51pub use chunked_upload::{
52 ChunkedUploadError, ChunkedUploadManager, ChunkedUploadSession, UploadProgress,
53};
54pub use extensions::Extensions;
55#[cfg(feature = "messages")]
56pub use messages_middleware::MessagesMiddleware;
57pub use middleware::{Handler, Middleware, MiddlewareChain};
58pub use request::{Request, RequestBuilder, TrustedProxies};
59pub use response::{Response, SafeErrorResponse, StreamBody, StreamingResponse};
60pub use upload::{FileUploadError, FileUploadHandler, MemoryFileUpload, TemporaryFileUpload};
61
62// Re-export error types from reinhardt-exception for consistency across the framework
63pub use reinhardt_core::exception::{Error, Result};
64
65/// A convenient type alias for view/endpoint function return types.
66///
67/// This type alias is commonly used in endpoint handlers to simplify function signatures.
68/// It wraps any type `T` (typically `Response`) with a dynamic error type that can
69/// represent various kinds of errors that might occur during request processing.
70///
71/// The `Send + Sync` bounds ensure this type is safe to use across thread boundaries,
72/// which is essential for async runtime environments.
73///
74/// # Examples
75///
76/// ```
77/// use reinhardt_http::{Response, ViewResult};
78///
79/// async fn hello_world() -> ViewResult<Response> {
80/// Ok(Response::ok().with_body("Hello, World!"))
81/// }
82///
83/// #[tokio::main]
84/// # async fn main() {
85/// let response = hello_world().await.unwrap();
86/// assert_eq!(response.status, hyper::StatusCode::OK);
87/// # }
88/// ```
89/// Result type for view handlers using reinhardt's unified Error type.
90///
91/// This type alias ensures compatibility with `UnifiedRouter::function` which requires
92/// `Future<Output = Result<Response>>` where `Result` is `reinhardt_core::exception::Result`.
93pub type ViewResult<T> = reinhardt_core::exception::Result<T>;