Crates.io | jsonrpc_client |
lib.rs | jsonrpc_client |
version | 0.7.1 |
source | src |
created_at | 2018-08-24 07:10:57.206866 |
updated_at | 2021-08-26 01:33:17.079641 |
description | An async, macro-driven JSON-RPC client with pluggable backends. |
homepage | |
repository | https://github.com/thomaseizinger/rust-jsonrpc-client |
max_upload_size | |
id | 81012 |
size | 100,609 |
We take a trait as input to a proc-macro and output another one that has default implementations for all the functions. This allows us to take away all the boilerplate of making JSON-RPC calls and you get to define a nice interface at the same time!
Depend on jsonrpc_client
:
[dependencies]
jsonrpc_client = { version = "*", features = ["reqwest"] }
Define a trait that describes the JSON-RPC API you want to talk to and annotate it with #[jsonrpc_client::api]
:
#[jsonrpc_client::api]
pub trait Math {
async fn subtract(&self, subtrahend: i64, minuend: i64) -> i64;
}
Define your client:
#[jsonrpc_client::implement(Math)]
struct Client {
inner: reqwest::Client,
base_url: reqwest::Url,
}
Start using your client!
Currently, the client supports several backends, all of them can be activated via a separate feature-flag:
Support for more backends is welcomed.
Unfortunately, not all can be supported. In particular:
Agent
takes &mut self
for sending a request which doesn't work with the SendRequest
trait.Client
does not implement Send
.