Crate workflow_rpc

source ·
Expand description

github crates.io docs.rs license //! async Rust-centric RPC framework supporting a custom high-performance Borsh and an extended JSON-RPC protocols.

Features:

  • High-performance Borsh message encoding protocol
  • RPC method and notification handler declarations based on serializable generics
  • Client to Server RPC method invocation
  • Client to Server notification messages
  • Server to Client notification messages
  • Server-side handshake scaffolding for custom connection negotiation
  • Easy to retain connection data structure for posting async client notifications

This framework provides server and client modules. The server infrastructure is built on top of Tokio and Tungtenite and provides scaffolding for connection handshake negotiation.

The client is built on top of Workflow WebSocket and operates uniformly in native applications and in the browser WASM environment. For native applications Workflow Websocket uses Tokio and Tungstenite and in the browser environment it uses the browser WebSocket object.

§Client-side

    interface.notification(
        TestOps::Notify,
        notification!(|notification: TestNotify| async move {
            // handle notification
            Ok(())
        }),
    );
     
    let resp: MyResponse = rpc.call(MyOps::MyMethod, MethodRequest { ... }).await?;

§Server-side

    interface.method(
        TestOps::SomeRequest,
        method!(|connection_ctx, server_ctx, request: TestReq| async move {
            // handle request and return a response
            Ok(SomeResponse { })
        }),
    );
     
    interface.notification(
        TestOps::Notify,
        notification!(
            |connection_ctx, server_ctx, notification: TestNotify| async move {
                // handle notification
                Ok(())
            }
        ),
    );
     

Modules§