#rpc #web #macro #arpy

macro arpy-macros

Macros for the Arpy RPC library

2 unstable releases

0.2.0 Jul 31, 2023
0.1.0 Feb 1, 2023

#437 in #rpc

Download history 21/week @ 2023-12-15 15/week @ 2023-12-22 3/week @ 2023-12-29 29/week @ 2024-01-05 28/week @ 2024-01-12 8/week @ 2024-01-19 6/week @ 2024-01-26 11/week @ 2024-02-02 11/week @ 2024-02-09 36/week @ 2024-02-16 52/week @ 2024-02-23 55/week @ 2024-03-01 40/week @ 2024-03-08 31/week @ 2024-03-15 38/week @ 2024-03-22 42/week @ 2024-03-29

154 downloads per month
Used in 7 crates (via arpy)

MIT/Apache

5KB

Arpy: RPC for Rust

tests crates.io Documentation MIT/Apache-2 licensed

Define your RPC signatures, and use them with various client/server implementations.

Project Status

Arpy is in it's infancy, and not well tested yet.

Transport Implementations

Reqwest and Reqwasm clients are available, along with Axum and Actix servers.

Usage

Define your RPC signatures, implement them on the server, and call them on the client. These can be in separate crates, or all in one depending on your workflow.

Defining RPC Signatures

#[derive(MsgId, Serialize, Deserialize, Debug)]
pub struct Add(pub i32, pub i32);

impl FnRemote for Add {
    type Output = i32;
}

#[derive(MsgId, Serialize, Deserialize, Debug)]
pub struct TryMultiply(pub i32, pub i32);

impl FnRemote for TryMultiply {
    type Output = Result<i32, ()>;
}

Implementing a Server

Example using Axum:

async fn add(args: &Add) -> i32 {
    args.0 + args.1
}

async fn try_multiply(args: &TryMultiply) -> Result<i32, ()> {
    Ok(args.0 * args.1)
}

let app = Router::new()
    .http_rpc_route("/http", add)
    .http_rpc_route("/http", try_multiply);

Server::bind(&SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 9090))
    .serve(app.into_make_service())
    .await
    .unwrap();

Calling Remote Procedures

Example using Reqwasm:

let connection = http::Connection::new(&format!("http://127.0.0.1:9090/api"));
let result = Add(1, 2).call(&connection).await?;

assert_eq!(3, result);

Other Features

  • Websockets support, including:
    • multiple in flight RPC calls
    • parameterized subscriptions
  • Server sent events

Dependencies

~1.5MB
~34K SLoC