aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc/examples/client.rs
blob: 2c8cf831129037eba15c455aeebc6a9910ca7e0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use serde::{Deserialize, Serialize};
use smol::net::TcpStream;

use karyon_jsonrpc::{Client, ClientConfig};

#[derive(Deserialize, Serialize)]
struct Req {
    x: u32,
    y: u32,
}

#[derive(Deserialize, Serialize, Debug)]
struct Pong {}

fn main() {
    env_logger::init();
    smol::future::block_on(async {
        let conn = TcpStream::connect("127.0.0.1:60000").await.unwrap();
        let config = ClientConfig::default();
        let client = Client::new(conn, config);

        let params = Req { x: 10, y: 7 };
        let result: u32 = client.call("Calc.add", params).await.unwrap();
        println!("result {result}");

        let params = Req { x: 10, y: 7 };
        let result: u32 = client.call("Calc.sub", params).await.unwrap();
        println!("result {result}");

        let result: Pong = client.call("Calc.ping", ()).await.unwrap();
        println!("result {:?}", result);

        let result: String = client.call("Calc.version", ()).await.unwrap();
        println!("result {result}");
    });
}