Skip to main content

HttpIngress

Struct HttpIngress 

Source
pub struct HttpIngress<R = ()> { /* private fields */ }
Expand description

HTTP Ingress Circuit Builder.

Wires HTTP inputs to Ranvier Circuits. This is NOT a web server—it’s a circuit wiring tool.

Ingress is part of Schematic (separate layer: Ingress → Circuit → Egress)

Implementations§

Source§

impl<R> HttpIngress<R>
where R: ResourceRequirement + Clone + Send + Sync + 'static,

Source

pub fn new() -> Self

Create a new empty HttpIngress builder.

Source

pub fn bind(self, addr: impl Into<String>) -> Self

Set the bind address for the server.

Source

pub fn on_start<F>(self, callback: F) -> Self
where F: Fn() + Send + Sync + 'static,

Register a lifecycle callback invoked when the server starts listening.

Source

pub fn on_shutdown<F>(self, callback: F) -> Self
where F: Fn() + Send + Sync + 'static,

Register a lifecycle callback invoked after graceful shutdown completes.

Source

pub fn graceful_shutdown(self, timeout: Duration) -> Self

Configure graceful shutdown timeout for in-flight request draining.

Source

pub fn layer<L>(self, layer: L) -> Self
where L: Layer<BoxCloneService<Request<Incoming>, HttpResponse, Infallible>> + Clone + Send + Sync + 'static, L::Service: Service<Request<Incoming>, Response = HttpResponse, Error = Infallible> + Clone + Send + 'static, <L::Service as Service<Request<Incoming>>>::Future: Send + 'static,

Add a global Tower layer to the ingress service stack.

Layers execute in LIFO order on the request path: the last layer added is the first to receive the request.

Source

pub fn timeout_layer(self, timeout: Duration) -> Self

Add built-in timeout middleware that returns 408 Request Timeout when the inner service call exceeds timeout.

Source

pub fn request_id_layer(self) -> Self

Add built-in request-id middleware.

Ensures x-request-id exists on request and response headers.

Source

pub fn bus_injector<F>(self, injector: F) -> Self
where F: Fn(&Request<Incoming>, &mut Bus) + Send + Sync + 'static,

Register a request-context injector executed before each circuit run.

Use this to bridge adapter-layer context (request extensions/headers) into explicit Bus resources consumed by Transitions.

Source

pub fn route_descriptors(&self) -> Vec<HttpRouteDescriptor>

Export route metadata snapshot for external tooling.

Source

pub fn serve_dir( self, route_prefix: impl Into<String>, directory: impl Into<String>, ) -> Self

Mount a static directory under a path prefix.

Example: .serve_dir("/static", "./public").

Source

pub fn spa_fallback(self, file_path: impl Into<String>) -> Self

Configure SPA fallback file for unmatched GET/HEAD routes.

Example: .spa_fallback("./public/index.html").

Source

pub fn static_cache_control(self, cache_control: impl Into<String>) -> Self

Override default Cache-Control for static responses.

Source

pub fn compression_layer(self) -> Self

Add gzip/brotli response compression via tower-http::CompressionLayer.

Source

pub fn ws<H, Fut>(self, path: impl Into<String>, handler: H) -> Self
where H: Fn(WebSocketConnection, Arc<R>, Bus) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,

Register a WebSocket upgrade endpoint and session handler.

The handler receives:

  1. a WebSocketConnection implementing EventSource/EventSink,
  2. shared resources (Arc<R>),
  3. a connection-scoped Bus with request injectors + WebSocketSessionContext.
Source

pub fn health_endpoint(self, path: impl Into<String>) -> Self

Enable built-in health endpoint at the given path.

The endpoint returns JSON with status and check results. If no checks are registered, status is always ok.

Source

pub fn health_check<F, Fut, Err>( self, name: impl Into<String>, check: F, ) -> Self
where F: Fn(Arc<R>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), Err>> + Send + 'static, Err: ToString + Send + 'static,

Register an async health check used by /health and /ready probes.

Err values are converted to strings and surfaced in the JSON response.

Source

pub fn readiness_liveness( self, readiness_path: impl Into<String>, liveness_path: impl Into<String>, ) -> Self

Enable readiness/liveness probe separation with explicit paths.

Source

pub fn readiness_liveness_default(self) -> Self

Enable readiness/liveness probes at /ready and /live.

Source

pub fn route<Out, E>( self, path: impl Into<String>, circuit: Axon<(), Out, E, R>, ) -> Self
where Out: IntoResponse + Send + Sync + 'static, E: Send + 'static + Debug,

Register a route with GET method.

Source

pub fn route_method<Out, E>( self, method: Method, path: impl Into<String>, circuit: Axon<(), Out, E, R>, ) -> Self
where Out: IntoResponse + Send + Sync + 'static, E: Send + 'static + Debug,

Register a route with a specific HTTP method.

§Example
Ranvier::http()
    .route_method(Method::POST, "/users", create_user_circuit)
Source

pub fn route_method_with_error<Out, E, H>( self, method: Method, path: impl Into<String>, circuit: Axon<(), Out, E, R>, error_handler: H, ) -> Self
where Out: IntoResponse + Send + Sync + 'static, E: Send + 'static + Debug, H: Fn(&E) -> HttpResponse + Send + Sync + 'static,

Source

pub fn route_method_with_layer<Out, E, L>( self, method: Method, path: impl Into<String>, circuit: Axon<(), Out, E, R>, layer: L, ) -> Self
where Out: IntoResponse + Send + Sync + 'static, E: Send + 'static + Debug, L: Layer<BoxCloneService<Request<Incoming>, HttpResponse, Infallible>> + Clone + Send + Sync + 'static, L::Service: Service<Request<Incoming>, Response = HttpResponse, Error = Infallible> + Clone + Send + 'static, <L::Service as Service<Request<Incoming>>>::Future: Send + 'static,

Source

pub fn route_method_with_layer_override<Out, E, L>( self, method: Method, path: impl Into<String>, circuit: Axon<(), Out, E, R>, layer: L, ) -> Self
where Out: IntoResponse + Send + Sync + 'static, E: Send + 'static + Debug, L: Layer<BoxCloneService<Request<Incoming>, HttpResponse, Infallible>> + Clone + Send + Sync + 'static, L::Service: Service<Request<Incoming>, Response = HttpResponse, Error = Infallible> + Clone + Send + 'static, <L::Service as Service<Request<Incoming>>>::Future: Send + 'static,

Source

pub fn get<Out, E>( self, path: impl Into<String>, circuit: Axon<(), Out, E, R>, ) -> Self
where Out: IntoResponse + Send + Sync + 'static, E: Send + 'static + Debug,

Source

pub fn get_with_error<Out, E, H>( self, path: impl Into<String>, circuit: Axon<(), Out, E, R>, error_handler: H, ) -> Self
where Out: IntoResponse + Send + Sync + 'static, E: Send + 'static + Debug, H: Fn(&E) -> HttpResponse + Send + Sync + 'static,

Source

pub fn get_with_layer<Out, E, L>( self, path: impl Into<String>, circuit: Axon<(), Out, E, R>, layer: L, ) -> Self
where Out: IntoResponse + Send + Sync + 'static, E: Send + 'static + Debug, L: Layer<BoxCloneService<Request<Incoming>, HttpResponse, Infallible>> + Clone + Send + Sync + 'static, L::Service: Service<Request<Incoming>, Response = HttpResponse, Error = Infallible> + Clone + Send + 'static, <L::Service as Service<Request<Incoming>>>::Future: Send + 'static,

Source

pub fn get_with_layer_override<Out, E, L>( self, path: impl Into<String>, circuit: Axon<(), Out, E, R>, layer: L, ) -> Self
where Out: IntoResponse + Send + Sync + 'static, E: Send + 'static + Debug, L: Layer<BoxCloneService<Request<Incoming>, HttpResponse, Infallible>> + Clone + Send + Sync + 'static, L::Service: Service<Request<Incoming>, Response = HttpResponse, Error = Infallible> + Clone + Send + 'static, <L::Service as Service<Request<Incoming>>>::Future: Send + 'static,

Source

pub fn post<Out, E>( self, path: impl Into<String>, circuit: Axon<(), Out, E, R>, ) -> Self
where Out: IntoResponse + Send + Sync + 'static, E: Send + 'static + Debug,

Source

pub fn put<Out, E>( self, path: impl Into<String>, circuit: Axon<(), Out, E, R>, ) -> Self
where Out: IntoResponse + Send + Sync + 'static, E: Send + 'static + Debug,

Source

pub fn delete<Out, E>( self, path: impl Into<String>, circuit: Axon<(), Out, E, R>, ) -> Self
where Out: IntoResponse + Send + Sync + 'static, E: Send + 'static + Debug,

Source

pub fn patch<Out, E>( self, path: impl Into<String>, circuit: Axon<(), Out, E, R>, ) -> Self
where Out: IntoResponse + Send + Sync + 'static, E: Send + 'static + Debug,

Source

pub fn fallback<Out, E>(self, circuit: Axon<(), Out, E, R>) -> Self
where Out: IntoResponse + Send + Sync + 'static, E: Send + 'static + Debug,

Set a fallback circuit for unmatched routes.

§Example
let not_found = Axon::new("NotFound").then(|_| async { "404 Not Found" });
Ranvier::http()
    .route("/", home)
    .fallback(not_found)
Source

pub async fn run(self, resources: R) -> Result<(), Box<dyn Error + Send + Sync>>

Run the HTTP server with required resources.

Source

pub fn into_raw_service(self, resources: R) -> RawIngressService<R>

Convert to a raw Tower Service for integration with existing Tower stacks.

This is the “escape hatch” per Discussion 193:

“Raw API는 Flat API의 탈출구다.”

§Example
let ingress = Ranvier::http()
    .bind(":3000")
    .route("/", circuit);

let raw_service = ingress.into_raw_service();
// Use raw_service with existing Tower infrastructure

Trait Implementations§

Source§

impl<R> Default for HttpIngress<R>
where R: ResourceRequirement + Clone + Send + Sync + 'static,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<R> Freeze for HttpIngress<R>

§

impl<R = ()> !RefUnwindSafe for HttpIngress<R>

§

impl<R> Send for HttpIngress<R>
where R: Send,

§

impl<R> Sync for HttpIngress<R>
where R: Sync,

§

impl<R> Unpin for HttpIngress<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for HttpIngress<R>

§

impl<R = ()> !UnwindSafe for HttpIngress<R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more