Skip to main content

ranvier_http/
lib.rs

1//! # ranvier-http - HTTP Ingress Adapter for Ranvier
2//!
3//! This crate provides the **Hyper 1.0 native boundary layer** for Ranvier.
4//! It implements `Ranvier::http()` as an Ingress Circuit Builder (Discussion 193).
5//!
6//! ## Key Components
7//!
8//! - `Ranvier::http()` - Entry point for building HTTP ingress
9//! - `HttpIngress` - Builder for configuring routes and server
10//! - `RanvierService` - Hyper Service adapter for Axon execution
11//!
12//! ## Example
13//!
14//! ```rust,ignore
15//! use ranvier_core::prelude::*;
16//! use ranvier_http::prelude::*;
17//!
18//! let hello = Axon::new("Hello")
19//!     .then(|_| async { "Hello, Ranvier!" });
20//!
21//! Ranvier::http()
22//!     .bind("127.0.0.1:3000")
23//!     .route("/", hello)
24//!     .run()
25//!     .await?;
26//! ```
27
28pub mod extract;
29pub mod guard_integration;
30pub mod ingress;
31pub mod response;
32pub mod service;
33pub mod sse;
34
35#[cfg(feature = "http3")]
36pub mod http3;
37pub mod test_harness;
38
39pub use extract::{CookieJar, DEFAULT_BODY_LIMIT, ExtractError, FromRequest, Header, Json, Path, Query};
40pub use ingress::{
41    HttpIngress, HttpRouteDescriptor, PathParams, Ranvier, WebSocketConnection, WebSocketError,
42    WebSocketEvent, WebSocketSessionContext,
43};
44pub use response::{
45    Html, HttpResponse, IntoProblemDetail, IntoResponse, ProblemDetail, json_error_response,
46    outcome_to_problem_response, outcome_to_response, outcome_to_response_with_error,
47};
48pub use guard_integration::{
49    BusInjectorFn, GuardExec, GuardIntegration, GuardRejection, PreflightConfig, RegisteredGuard,
50    ResponseBodyTransformFn, ResponseExtractorFn,
51};
52pub use service::RanvierService;
53pub use sse::{Sse, SseEvent};
54pub use test_harness::{TestApp, TestHarnessError, TestRequest, TestResponse};
55
56/// Collects Guard registrations for per-route Guard configuration.
57///
58/// Returns a `Vec<RegisteredGuard>` for use with `post_with_guards()`,
59/// `get_with_guards()`, and other per-route Guard methods.
60///
61/// # Example
62///
63/// ```rust,ignore
64/// use ranvier_http::guards;
65/// use ranvier_guard::prelude::*;
66///
67/// Ranvier::http()
68///     .guard(AccessLogGuard::new())  // global guard
69///     .post_with_guards("/api/orders", order_circuit, guards![
70///         ContentTypeGuard::json(),
71///         IdempotencyGuard::ttl_5min(),
72///     ])
73///     .get("/api/orders", list_circuit)  // no extra guards
74/// ```
75#[macro_export]
76macro_rules! guards {
77    [$($guard:expr),* $(,)?] => {
78        vec![$( $crate::GuardIntegration::register($guard) ),*]
79    };
80}
81
82/// Prelude module for convenient imports
83pub mod prelude {
84    pub use crate::extract::{CookieJar, DEFAULT_BODY_LIMIT, ExtractError, FromRequest, Header, Json, Path, Query};
85    pub use crate::ingress::{
86        HttpIngress, HttpRouteDescriptor, PathParams, Ranvier, WebSocketConnection, WebSocketError,
87        WebSocketEvent, WebSocketSessionContext,
88    };
89    pub use crate::response::{
90        Html, HttpResponse, IntoProblemDetail, IntoResponse, ProblemDetail, json_error_response,
91        outcome_to_problem_response, outcome_to_response, outcome_to_response_with_error,
92    };
93    pub use crate::guard_integration::{
94        BusInjectorFn, GuardExec, GuardIntegration, GuardRejection, PreflightConfig,
95        RegisteredGuard, ResponseBodyTransformFn, ResponseExtractorFn,
96    };
97    pub use crate::service::RanvierService;
98    pub use crate::sse::{Sse, SseEvent};
99    pub use crate::test_harness::{TestApp, TestHarnessError, TestRequest, TestResponse};
100}