Crates.io | tetsy-jsonrpc-core |
lib.rs | tetsy-jsonrpc-core |
version | 15.1.0 |
source | src |
created_at | 2021-03-01 07:37:01.961717 |
updated_at | 2021-03-13 03:23:09.828614 |
description | Tetsy Transport agnostic rust implementation of JSON-RPC 2.0 Specification. |
homepage | https://core.tetcoin.org |
repository | https://github.com/tetcoin/tetsy-jsonrpc |
max_upload_size | |
id | 362102 |
size | 67,254 |
Transport agnostic rust implementation of JSON-RPC 2.0 Specification.
Cargo.toml
[dependencies]
tetsy-jsonrpc-core = "4.0"
main.rs
use tetsy_jsonrpc_core::*;
fn main() {
let mut io = IoHandler::default();
io.add_method("say_hello", |_params: Params| {
Ok(Value::String("hello".into()))
});
let request = r#"{"jsonrpc": "2.0", "method": "say_hello", "params": [42, 23], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"hello","id":1}"#;
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
}
main.rs
use tetsy_jsonrpc_core::*;
use tetsy_jsonrpc_core::futures::Future;
fn main() {
let io = IoHandler::new();
io.add_async_method("say_hello", |_params: Params| {
futures::finished(Value::String("hello".into()))
});
let request = r#"{"jsonrpc": "2.0", "method": "say_hello", "params": [42, 23], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"hello","id":1}"#;
assert_eq!(io.handle_request(request).wait().unwrap(), Some(response.to_owned()));
}
See examples directory.