jsonrpce 0.1.0

JSON-RPC 2.0 for Rust
Documentation
  • Coverage
  • 34.62%
    9 out of 26 items documented0 out of 2 items with examples
  • Size
  • Source code size: 39.8 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.2 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 17s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • pyk

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