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 = "htmx")]
36pub mod htmx;
37#[cfg(feature = "http3")]
38pub mod http3;
39pub mod test_harness;
40
41pub use extract::{CookieJar, DEFAULT_BODY_LIMIT, ExtractError, FromRequest, Header, Json, Path, Query};
42pub use ingress::{
43    HttpIngress, HttpRouteDescriptor, PathParams, Ranvier, WebSocketConnection, WebSocketError,
44    WebSocketEvent, WebSocketSessionContext,
45};
46pub use response::{
47    Html, HttpResponse, IntoProblemDetail, IntoResponse, ProblemDetail, json_error_response,
48    outcome_to_problem_response, outcome_to_response, outcome_to_response_with_error,
49};
50pub use guard_integration::{
51    BusInjectorFn, GuardExec, GuardIntegration, GuardRejection, PreflightConfig, RegisteredGuard,
52    ResponseBodyTransformFn, ResponseExtractorFn,
53};
54pub use service::RanvierService;
55pub use sse::{Sse, SseEvent};
56pub use test_harness::{TestApp, TestHarnessError, TestRequest, TestResponse};
57
58/// Collects Guard registrations for per-route Guard configuration.
59///
60/// Returns a `Vec<RegisteredGuard>` for use with `post_with_guards()`,
61/// `get_with_guards()`, and other per-route Guard methods.
62///
63/// # Example
64///
65/// ```rust,ignore
66/// use ranvier_http::guards;
67/// use ranvier_guard::prelude::*;
68///
69/// Ranvier::http()
70///     .guard(AccessLogGuard::new())  // global guard
71///     .post_with_guards("/api/orders", order_circuit, guards![
72///         ContentTypeGuard::json(),
73///         IdempotencyGuard::ttl_5min(),
74///     ])
75///     .get("/api/orders", list_circuit)  // no extra guards
76/// ```
77#[macro_export]
78macro_rules! guards {
79    [$($guard:expr),* $(,)?] => {
80        vec![$( $crate::GuardIntegration::register($guard) ),*]
81    };
82}
83
84/// Prelude module for convenient imports
85pub mod prelude {
86    pub use crate::extract::{CookieJar, DEFAULT_BODY_LIMIT, ExtractError, FromRequest, Header, Json, Path, Query};
87    pub use crate::ingress::{
88        HttpIngress, HttpRouteDescriptor, PathParams, Ranvier, WebSocketConnection, WebSocketError,
89        WebSocketEvent, WebSocketSessionContext,
90    };
91    pub use crate::response::{
92        Html, HttpResponse, IntoProblemDetail, IntoResponse, ProblemDetail, json_error_response,
93        outcome_to_problem_response, outcome_to_response, outcome_to_response_with_error,
94    };
95    pub use crate::guard_integration::{
96        BusInjectorFn, GuardExec, GuardIntegration, GuardRejection, PreflightConfig,
97        RegisteredGuard, ResponseBodyTransformFn, ResponseExtractorFn,
98    };
99    pub use crate::service::RanvierService;
100    pub use crate::sse::{Sse, SseEvent};
101    pub use crate::test_harness::{TestApp, TestHarnessError, TestRequest, TestResponse};
102}