jsonrpce

Crates.iojsonrpce
lib.rsjsonrpce
version0.1.0
created_at2025-12-18 11:16:59.425918+00
updated_at2025-12-18 11:16:59.425918+00
descriptionJSON-RPC 2.0 for Rust
homepage
repositoryhttps://github.com/bidentsec/jsonrpce
max_upload_size
id1992215
size39,764
pyk (pyk)

documentation

README

jsonrpc

JSON-RPC 2.0 implementation for Rust.

Features

  • Transport Agnostic: Decouples protocol logic from I/O. Comes with Stdio and InMemory transports out of the box.
  • Type-Safe Handlers: Handlers are just Rust functions. Parameters are automatically deserialized, and results are serialized.

Demo

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 }

Installation

TODO: add installation via git

Usage

TODO: add usage

License

MIT

Commit count: 0

cargo fmt