| Crates.io | jsonrpce |
| lib.rs | jsonrpce |
| version | 0.1.0 |
| created_at | 2025-12-18 11:16:59.425918+00 |
| updated_at | 2025-12-18 11:16:59.425918+00 |
| description | JSON-RPC 2.0 for Rust |
| homepage | |
| repository | https://github.com/bidentsec/jsonrpce |
| max_upload_size | |
| id | 1992215 |
| size | 39,764 |
JSON-RPC 2.0 implementation for Rust.
Stdio
and InMemory transports out of the box.Let's build a simple calculator server over Stdio:
use serde::Deserialize;
use jsonrpc::{Error, Server};
#[derive(Deserialize)]
struct AddParams {
a: i32,
b: i32,
}
fn add(_: &(), params: AddParams) -> Result<i32, Error> {
Ok(params.a + params.b)
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
Server::stdio(()).method("add", add).run()?;
Ok(())
}
Compile and run it, then pipe in some JSON-RPC commands:
echo '{"jsonrpc": "2.0", "method": "add", "params": {"a": 10, "b": 20}, "id": 1}' | cargo run --example stdio
Output:
{ "jsonrpc": "2.0", "result": 30, "id": 1 }
TODO: add installation via git
TODO: add usage
MIT