A Rust implementation of the JSON-RPC 2.0 specification.
nimiq-jsonrpc-coreimplements the data structures (using serde) for JSON-RPC.nimiq-jsonrpc-clientis a client implementation for a HTTP (using reqwest) and websocket client (using tokio-tungstenite).nimiq-jsonrpc-serveris a server implementation for HTTP and websocket (using warp).
use async_trait::async_trait;
use serde::{Serialize, Deserialize};
use nimiq_jsonrpc_server::{Server, Config};
use nimiq_jsonrpc_client::http::HttpClient;
#[nimiq_jsonrpc_derive::proxy]
#[async_trait]
trait Foobar {
    async fn hello(&self, name: String) -> String;
}
struct FoobarService;
#[nimiq_jsonrpc_derive::service]
#[async_trait]
impl Foobar for FoobarService {
    async fn hello(&self, name: String) -> String {
        println!("Hello, {}", name);
        format!("Hello, {}", name)
    }
}
#[tokio::main]
async fn main() {
    dotenvy::dotenv().ok();
    pretty_env_logger::init();
    let config = Config::default();
    log::info!("Listening on: {}", config.bind_to);
    let server = Server::new(config, FoobarService);
    tokio::spawn(async move {
        server.run().await;
    });
    let client = HttpClient::new("http://localhost:8000/");
    let mut proxy = FoobarProxy::new(client);
    let retval = proxy.hello("World".to_owned()).await;
    log::info!("RPC call returned: {}", retval);
}- [_] Share code between websocket clients.