#json-rpc #client #async-http-client #http #macro #proc-macro

jsonrpc_client

An async, macro-driven JSON-RPC client with pluggable backends

9 releases (breaking)

0.7.1 Aug 26, 2021
0.7.0 Jul 28, 2021
0.6.0 Apr 26, 2021
0.5.1 Feb 22, 2021
0.2.0 Oct 12, 2018

#188 in HTTP client

Download history 40/week @ 2024-07-19 42/week @ 2024-07-26 38/week @ 2024-08-02 52/week @ 2024-08-09 14/week @ 2024-08-16 45/week @ 2024-08-23 39/week @ 2024-08-30 20/week @ 2024-09-06 10/week @ 2024-09-13 40/week @ 2024-09-20 84/week @ 2024-09-27 42/week @ 2024-10-04 77/week @ 2024-10-11 47/week @ 2024-10-18 41/week @ 2024-10-25 58/week @ 2024-11-01

225 downloads per month
Used in 4 crates

MIT/Apache

26KB
493 lines

No bullshit JSON-RPC client for Rust

Features

  • No boilerplate: Driven by proc-macros
  • No client lock-in: Complete freedom over underlying HTTP client
  • Lightweight: Only depends on syn and serde
  • Async-ready

How does it work?

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!

How do I use it?

  1. Depend on jsonrpc_client:

    [dependencies]
    jsonrpc_client = { version = "*", features = ["reqwest"] }
    
  2. 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;
    }
    
  3. Define your client:

    #[jsonrpc_client::implement(Math)]
    struct Client {
        inner: reqwest::Client,
        base_url: reqwest::Url,
    }
    
  4. Start using your client!

Backends

Currently, the client supports several backends, all of them can be activated via a separate feature-flag:

  • reqwest
  • surf
  • isahc

Support for more backends is welcomed.

Unfortunately, not all can be supported. In particular:

  • hreq: Cannot be supported because their Agent takes &mut self for sending a request which doesn't work with the SendRequest trait.
  • awc: Cannot be supported because their Client does not implement Send.

Dependencies

~3–17MB
~230K SLoC