Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/broucz/minirpc
MINI-RPC is a stateless, light-weight remote procedure call (RPC) protocol
https://github.com/broucz/minirpc
Last synced: 22 days ago
JSON representation
MINI-RPC is a stateless, light-weight remote procedure call (RPC) protocol
- Host: GitHub
- URL: https://github.com/broucz/minirpc
- Owner: broucz
- License: mit
- Created: 2019-06-16T17:01:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-26T18:02:53.000Z (about 5 years ago)
- Last Synced: 2024-12-17T04:56:30.571Z (29 days ago)
- Language: Rust
- Homepage: https://docs.rs/minirpc/
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# minirpc
[![build_status]][travis]
[![latest_version]][crates_io]MINI-RPC is a stateless, light-weight remote procedure call (RPC) protocol. Inspired by the [JSON-RPC 2.0 Specification](https://www.jsonrpc.org/specification), this implementation written in Rust selected its essential parts in order to keep as minimal as possible the communication between processes.
[Documentation][documentation]
[build_status]: https://travis-ci.org/broucz/minirpc.svg?branch=master
[crates_io]: https://crates.io/crates/minirpc
[latest_version]: https://img.shields.io/crates/v/minirpc.svg
[travis]: https://travis-ci.org/broucz/minirpc
[documentation]: https://docs.rs/minirpc/## Examples
Syntax:
```
--> data sent to Server
<-- data sent to Client
```### Basic Usage
```
--> {"id":1,"method":"sum","params":[1,2,3]}
<-- {"id":1,"result":6}
``````rust
use minirpc::*;
use serde_json::*;// --> Request.
let input = r#"{"id":1,"method":"sum","params":[1,2,3]}"#;
let expected = Request::Single(RequestPayload::Call(Call {
id: Id::Number(1),
method: Method::String("sum".to_owned()),
params: Params::Array(vec![Value::from(1), Value::from(2), Value::from(3)]),
}));let result: Request = serde_json::from_str(input).unwrap();
assert_eq!(result, expected);// <-- Response.
let input = r#"{"id":1,"result":6}"#;
let expected = Response::Single(ResponsePayload::Success(Success {
id: Id::Number(1),
result: Value::Bool(true),
}));let result: Response = serde_json::from_str(input).unwrap();
assert_eq!(result, expected);
```### Batch Notification
```
--> [{"method":"log","params":{"level":"info"}},{"method":"log","params":{"level":"warn"}}]
``````rust
// --> Batch Request.
let input = r#"[{"method":"log","params":{"level":"info"}},{"method":"log","params":{"level":"warn"}}]"#;let mut params_1 = Map::new();
params_1.insert("level".to_string(), "info".into());let mut params_2 = Map::new();
params_2.insert("level".to_string(), "warn".into());let expected = Request::Batch(vec![
RequestPayload::Notification(Notification {
method: Method::String("log".to_owned()),
params: Params::Object(params_1),
}),
RequestPayload::Notification(Notification {
method: Method::String("log".to_owned()),
params: Params::Object(params_2),
}),
]);let result: Request = serde_json::from_str(input).unwrap();
assert_eq!(result, expected);
```