pub trait Middleware: Send + Sync + Clone + 'static {
    type Instant: Send + Copy;

    fn on_request(&self) -> Self::Instant;

    fn on_connect(&self) { ... }
    fn on_call(&self, _name: &str) { ... }
    fn on_result(&self, _name: &str, _success: bool, _started_at: Self::Instant) { ... }
    fn on_response(&self, _started_at: Self::Instant) { ... }
    fn on_disconnect(&self) { ... }
}
Expand description

Defines a middleware with callbacks during the RPC request life-cycle. The primary use case for this is to collect timings for a larger metrics collection solution but the only constraints on the associated type is that it be Send and Copy, giving users some freedom to do what they need to do.

See the WsServerBuilder::set_middleware or the HttpServerBuilder::set_middleware method for examples.

Required Associated Types

Intended to carry timestamp of a request, for example std::time::Instant. How the middleware measures time, if at all, is entirely up to the implementation.

Required Methods

Called when a new JSON-RPC comes to the server.

Provided Methods

Called when a new client connects (WebSocket only)

Called on each JSON-RPC method call, batch requests will trigger on_call multiple times.

Called on each JSON-RPC method completion, batch requests will trigger on_result multiple times.

Called once the JSON-RPC request is finished and response is sent to the output buffer.

Called when a client disconnects (WebSocket only)

Implementations on Foreign Types

Implementors