#json-rpc-client #rpc-client #json-rpc #rpc #json #web-client #client

jsonrpc_v2_awc

JSON RPC client based on awc (actix web client)

1 unstable release

0.1.0 Dec 11, 2021

#18 in #web-client

Apache-2.0

5KB

JSON RPC Client - Based on awc crate (actix web client)

Examples

// call to remote function `mul` taking 2 numbers, they can be u8, f32, etc
println!(
    "2 + 3 = {:?}",
    jsonrpc_v2_awc::Request::new("mul", jsonrpc_v2_awc::Params([2, 3]), 0)
        .send("http://localhost:8082/api")
        .await?
        .body()
        .await?
);

// call to remote function `timestamp` with no params, in this case params can be () or ""
println!(
    "2 + 3 = {:?}",
    jsonrpc_v2_awc::Request::new("timestamp", jsonrpc_v2_awc::Params(()), 1)
        .send("http://localhost:8082/api")
        .await?
        .body()
        .await?
);

// call to remote function `timestamp` with no params, using api_key
println!(
    "2 + 3 = {:?}",
    jsonrpc_v2_awc::Request::new("timestamp", jsonrpc_v2_awc::Params(()), 1)
        .send_with_api_key("http://localhost:8082/api", "API_KEY", "ds09ds9d-0d9s0d.xxx.yyy")
        .await?
        .body()
        .await?
);


lib.rs:

JSON RPC Client

This library provides a way to send JSON RPC requests, there are 2 options, without api_key and with api_key which sets request header API_KEY

Examples

// call to remote function `mul` taking 2 numbers, they can be u8, f32, etc
println!(
    "2 + 3 = {:?}",
    jsonrpc_v2_awc::Request::new("mul", jsonrpc_v2_awc::Params([2, 3]), 0)
        .send("http://localhost:8082/api")
        .await?
        .body()
        .await?
);

// call to remote function `timestamp` with no params, in this case params can be () or ""
println!(
    "2 + 3 = {:?}",
    jsonrpc_v2_awc::Request::new("timestamp", jsonrpc_v2_awc::Params(()), 1)
        .send("http://localhost:8082/api")
        .await?
        .body()
        .await?
);

// call to remote function `timestamp` with no params, using api_key
println!(
    "2 + 3 = {:?}",
    jsonrpc_v2_awc::Request::new("timestamp", jsonrpc_v2_awc::Params(()), 1)
        .send_with_api_key("http://localhost:8082/api", "API_KEY", "ds09ds9d-0d9s0d.xxx.yyy")
        .await?
        .body()
        .await?
);

Dependencies

~25MB
~543K SLoC