ZenWebsocket.Examples.Docs.JsonRpcClient (ZenWebsocket v0.1.4)
View SourceJSON-RPC client example from documentation.
Demonstrates how to make JSON-RPC calls over WebSocket connections. The ZenWebsocket.Client automatically handles request/response correlation for JSON-RPC messages - no manual correlation needed!
Summary
Functions
Makes a synchronous JSON-RPC call.
Makes an async JSON-RPC call without waiting for response.
Echo test method
Get account balance
Get server timestamp
Processes incoming WebSocket messages and returns JSON-RPC responses.
Functions
@spec call_method(ZenWebsocket.Client.t(), String.t(), map() | nil, timeout()) :: {:ok, term()} | {:error, term()}
Makes a synchronous JSON-RPC call.
The Client automatically handles JSON-RPC correlation - when sending a message with an "id" field, it tracks the request and returns the correlated response.
@spec cast_method(ZenWebsocket.Client.t(), String.t(), map() | nil) :: :ok | {:error, term()}
Makes an async JSON-RPC call without waiting for response.
Echo test method
Get account balance
Get server timestamp
Processes incoming WebSocket messages and returns JSON-RPC responses.