3 releases (breaking)

0.3.0 Dec 28, 2018
0.2.0 Jul 16, 2018
0.1.0 Jun 25, 2018

#18 in #server-response

38 downloads per month
Used in rpc-cli

MIT license

10KB
244 lines

#rpc-lib

This is an RPC 2.0 library for making requests to a server, it has been modified to handle some non-standard server responses such as, string error return value.

Why not strict RPC 2.0 responses

Because I am supporting some legacy Go RPC server that are slightly off spec, however, this will also support the proper RPC 2.0 spec.

Requirements

On Linux:

On Windows and macOS:

  • Nothing.

Usage

First, add this to your Cargo.toml:

[dependencies]
rpc-lib = "1.0.0"

Here is a quite example to get you going:

extern crate rpc_lib;
extern crate serde;
#[macro_use]
extern crate serde_derive;

use rpc_lib::client::prelude::*;
use std::error::Error;

#[derive(Serialize)]
struct Input {
    id: String,
}

#[derive(Deserialize, Debug)]
struct Project {
    id: String,
    url: String,
    enabled: bool,
}

fn main() -> Result<(), Box<Error>> {
    let input = Input {
        id: "x0x0x0x0".to_string(),
    };
    let client = Client::new("http://localhost:4000/rpc");
    let res: Project = client.call("1", "Project.Find", input)?;
    println!("{:?}", res);
    Ok(())
}

Dependencies

~20MB
~447K SLoC