nimiq/jsonrpc

A Rust implementation of the JSON-RPC 2

A Rust implementation of the serde) for JSON-RPC

Nimiq JSON-RPC

A Rust implementation of the JSON-RPC 2.0 specification.

  • nimiq-jsonrpc-core implements the data structures (using serde) for JSON-RPC.
  • nimiq-jsonrpc-client is a client implementation for a HTTP (using reqwest) and websocket client (using tokio-tungstenite).
  • nimiq-jsonrpc-server is a server implementation for HTTP and websocket (using warp).

Example

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(&mut self, name: String) -> String;
}

struct FoobarService;

#[nimiq_jsonrpc_derive::service]
#[async_trait]
impl Foobar for FoobarService {
    async fn hello(&mut self, name: String) -> String {
        println!("Hello, {}", name);
        format!("Hello, {}", name)
    }
}


#[tokio::main]
async fn main() {
    dotenv::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);
}

TODO

  • [_] Share code between websocket clients.
Issues

Collection of the latest Issues

jgraef

jgraef

Comment Icon1

Add support for optional arguments. We can either somehow interpret Option<T> arguments as optional or maybe add an attribute #[default] to tell the dispatcher-derive to use unwrap_or_default for this argument.

Information - Updated Jul 06, 2022

Stars: 5
Forks: 1
Issues: 1

Repositories & Extras

Http

5.9K

An ergonomic, batteries-included HTTP Client for Rust

optional features, so your Cargo

An ergonomic, batteries-included HTTP Client for Rust

Ease - HTTP clients for Rust

Ease is a library for interacting with RESTful APIs

Ease - HTTP clients for Rust
Http

543

Say hello to Isahc (pronounced like Isaac), the practical HTTP client that is fun to...

Say hello to Isahc (pronounced like Isaac), the practical HTTP client that is fun to use

Say hello to Isahc (pronounced like Isaac), the practical HTTP client that is fun to...
Http

1.0K

A simple, safe HTTP client

Ureq's first priority is being easy for you to use

A simple, safe HTTP client

Roctogen: a rust client library for the GitHub v3 API

This client API is generated from the Isahc HTTP client

Roctogen: a rust client library for the GitHub v3 API
Http

102

Types and traits for http clients

cargo add installed run:

Types and traits for http clients

ehttp: a minimal Rust HTTP client for both native and WASM

If you want to do HTTP requests and are targetting both native and web (WASM), then this is the crate for you!

ehttp: a minimal Rust HTTP client for both native and WASM

APIX is a modern HTTP client for the command line

Bat to pretty print requests and responses

APIX is a modern HTTP client for the command line

![CI]( Simple, minimal-dependency HTTP client

This is a list of features I'll implement once it gets long enough, or

![CI]( Simple, minimal-dependency HTTP client

httpc is a Rust library crate providing an HTTP client that works

When targeting WASM it works directly with the

httpc is a Rust library crate providing an HTTP client that works
Facebook Instagram Twitter GitHub Dribbble
Privacy