Crates.io | arpy-server |
lib.rs | arpy-server |
version | 0.2.0 |
source | src |
created_at | 2023-02-01 21:12:25.862651 |
updated_at | 2023-07-31 12:00:58.316415 |
description | Actix server for the Arpy |
homepage | https://github.com/simon-bourne/arpy |
repository | https://github.com/simon-bourne/arpy |
max_upload_size | |
id | 774203 |
size | 18,852 |
Define your RPC signatures, and use them with various client/server implementations.
Arpy is in it's infancy, and not well tested yet.
Reqwest and Reqwasm clients are available, along with Axum and Actix servers.
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.
#[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, ()>;
}
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();
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);