31 releases

new 0.14.0 Nov 29, 2022
0.13.0 Jul 22, 2022
0.12.1 Jan 20, 2022
0.12.0 Jan 5, 2021
0.6.2 Nov 23, 2015

#92 in Network programming

Download history 5816/week @ 2022-08-11 4785/week @ 2022-08-18 5664/week @ 2022-08-25 4897/week @ 2022-09-01 4567/week @ 2022-09-08 4101/week @ 2022-09-15 3816/week @ 2022-09-22 4180/week @ 2022-09-29 4242/week @ 2022-10-06 3384/week @ 2022-10-13 3764/week @ 2022-10-20 3954/week @ 2022-10-27 5237/week @ 2022-11-03 4384/week @ 2022-11-10 4167/week @ 2022-11-17 3621/week @ 2022-11-24

17,988 downloads per month
Used in 51 crates (16 directly)

CC0 license

66KB
1.5K SLoC

Status

Rust Version compatibility

This library is compatible with Rust 1.41.1 or higher.

Rust JSONRPC Client

Rudimentary support for sending JSONRPC 2.0 requests and receiving responses.

As an example, hit a local bitcoind JSON-RPC endpoint and call the uptime command.

use jsonrpc::Client;
use jsonrpc::simple_http::{self, SimpleHttpTransport};

fn client(url: &str, user: &str, pass: &str) -> Result<Client, simple_http::Error> {
    let t = SimpleHttpTransport::builder()
        .url(url)?
        .auth(user, Some(pass))
        .build();

    Ok(Client::with_transport(t))
}

// Demonstrate an example JSON-RCP call against bitcoind.
fn main() {
    let client = client("localhost:18443", "user", "pass").expect("failed to create client");
    let request = client.build_request("uptime", &[]);
    let response = client.send_request(request).expect("send_request failed");

    // For other commands this would be a struct matching the returned json.
    let result: u64 = response.result().expect("response is an error, use check_error");
    println!("bitcoind uptime: {}", result);
}

Githooks

To assist devs in catching errors before running CI we provide some githooks. If you do not already have locally configured githooks you can use the ones in this repository by running, in the root directory of the repository:

git config --local core.hooksPath githooks/

Alternatively add symlinks in your .git/hooks directory to any of the githooks we provide.

Dependencies

~0.6–1.4MB
~31K SLoC