1个不稳定版本
0.1.0 | 2021年12月11日 |
---|
#18 在 #web-client
5KB
基于awc crate(actix web client)的JSON RPC客户端
示例
// 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("https://127.0.0.1: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("https://127.0.0.1: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("https://127.0.0.1:8082/api", "API_KEY", "ds09ds9d-0d9s0d.xxx.yyy")
.await?
.body()
.await?
);
lib.rs
:
JSON RPC客户端
此库提供发送JSON RPC请求的方法,有两种选项,一种是不带api_key,另一种是带有api_key,它将请求头设置为API_KEY
示例
// 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("https://127.0.0.1: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("https://127.0.0.1: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("https://127.0.0.1:8082/api", "API_KEY", "ds09ds9d-0d9s0d.xxx.yyy")
.await?
.body()
.await?
);
依赖关系
~26MB
~549K SLoC