pub struct Client { /* private fields */ }Expand description
Unix-socket JSON-RPC client (one in-flight request per connection).
See the module docs for examples.
Implementations§
Source§impl Client
impl Client
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Start a ClientBuilder.
§Examples
use simplejrpc::Client;
let _ = Client::builder().socket("/tmp/app.sock");Sourcepub async fn connect(path: impl AsRef<Path>) -> Result<Self>
pub async fn connect(path: impl AsRef<Path>) -> Result<Self>
Dial a Unix socket and return a connected client.
§Examples
use simplejrpc::Client;
let client = Client::connect("/tmp/simplejrpc.sock").await?;Sourcepub fn from_stream(stream: UnixStream) -> Self
pub fn from_stream(stream: UnixStream) -> Self
Wrap an existing connected stream (tests / custom dialers).
§Examples
use simplejrpc::Client;
let _ = Client::from_stream(stream);Sourcepub fn next_request_id(&self) -> i64
pub fn next_request_id(&self) -> i64
Allocate the next monotonic JSON-RPC request id.
§Examples
use simplejrpc::Client;
let c = Client::connect("/tmp/simplejrpc.sock").await?;
assert_eq!(c.next_request_id(), 1);
assert_eq!(c.next_request_id(), 2);Sourcepub async fn call(&self, method: &str, params: Value) -> Result<Value>
pub async fn call(&self, method: &str, params: Value) -> Result<Value>
Call a method and return the app envelope data when code == 200.
If the envelope reports a non-200 code, returns Error::Biz with
that code and message (still a transport-level success).
§Examples
use simplejrpc::Client;
use serde_json::json;
let c = Client::connect("/tmp/simplejrpc.sock").await?;
let v = c.call("ping", json!({})).await?;Sourcepub async fn call_envelope(
&self,
method: &str,
params: Value,
) -> Result<AppResponse>
pub async fn call_envelope( &self, method: &str, params: Value, ) -> Result<AppResponse>
Call a method and return the full AppResponse envelope.
Use this when you need code / msg / meta (for example 404 method
missing still yields a JSON-RPC result, not a JSON-RPC error).
§Examples
use simplejrpc::Client;
use serde_json::json;
let c = Client::connect("/tmp/simplejrpc.sock").await?;
let env = c.call_envelope("missing", json!({})).await?;
assert_eq!(env.code, 404);Sourcepub async fn exchange_frame(&self, framed: &[u8]) -> Result<Vec<u8>>
pub async fn exchange_frame(&self, framed: &[u8]) -> Result<Vec<u8>>
Write one framed request and read exactly one framed response.
Exposed so wrappers can customize request building while reusing the locked stream exchange.
§Examples
use simplejrpc::client::encode_rpc_request;
use serde_json::json;
let framed = encode_rpc_request(1, "ping", json!({}))?;
let _body = c.exchange_frame(&framed).await?;