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