29 stable releases (8 major)

8.0.1 Dec 13, 2017
8.0.0 Nov 21, 2017
7.1.1 Sep 11, 2017
7.0.1 Jun 14, 2017
0.2.0 Jan 19, 2016

#2 in HTTP client

Download history 5734/week @ 2018-05-27 7263/week @ 2018-06-03 7123/week @ 2018-06-10 6334/week @ 2018-06-17 6785/week @ 2018-06-24 8543/week @ 2018-07-01 7430/week @ 2018-07-08 8495/week @ 2018-07-15 9008/week @ 2018-07-22 7605/week @ 2018-07-29 8765/week @ 2018-08-05 8410/week @ 2018-08-12 7980/week @ 2018-08-19

24,967 downloads per month
Used in 27 crates (21 directly)

MIT license

48KB
1K SLoC

jsonrpc-core

Transport agnostic rust implementation of JSON-RPC 2.0 Specification.

Documentation

  • - server side
  • - client side

Example

Cargo.toml

[dependencies]
jsonrpc-core = "4.0"

main.rs

extern crate jsonrpc_core;

use 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()));
}

Asynchronous responses

main.rs

extern crate jsonrpc_core;

use jsonrpc_core::*;
use 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()));
}

Publish-Subscribe

See examples directory.

Dependencies

~2MB
~45K SLoC