An open API service indexing awesome lists of open source software.

https://github.com/starcoinorg/openrpc-rs


https://github.com/starcoinorg/openrpc-rs

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

          

* openrpc-rs
Rust implementation of [[https://spec.open-rpc.org/][openrpc Specification]]

* Sub projects
+ [[https://github.com/starcoinorg/openrpc-rs/tree/master/openrpc-schema][openrpc-schema]]

Implement the schema of openrpc. Support to generate openrpc schema documents with the basic functions.
+ [[https://github.com/starcoinorg/openrpc-rs/tree/master/openrpc-derive][openrpc-derive]]

Implement a proc macro to generate openrpc schema for rust traits.

* Examples

Baisc Usage
#+begin_src rust
use jsonrpc_core::Error;
use openrpc_derive::openrpc;

#[openrpc]
pub trait DebugApi {

#[rpc(name = "debug.panic")]
fn panic(&self, me: String) -> Result;

#[rpc(name = "debug.sleep")]
fn sleep(&self, time: u64) -> Result;
}

fn main() {
let schema = self::gen_schema();
let j = serde_json::to_string_pretty(&schema).unwrap();
println!("{}", j);
}
#+end_src

Works with jsonrpc compatibly by adding the "jsonrpc" to the [features] section.
#+begin_src toml
openrpc-derive = {git = "https://github.com/starcoinorg/openrpc-rs",features=["jsonrpc"]}
#+end_src
This can generate both jsonrpc client and server, and openrpc schema.