#holochain #conductor #running #expanded #client #communicating #connect-ws

holochain-client-core

A client side rust library for communicating with a running Holochain conductor

1 unstable release

0.1.0 Feb 18, 2020

#5 in #expanded

MIT license

14KB
160 lines

Implements ConductorClient, a struct that implement RpcChannel and can therefore be used by the parity jsonrpc-core-client to produce a client instance that can make calls over any transport.

WARNING! - A limitation of the client macro in jsonrpc-core-client is preventing this from working properly The expanded and fixed macro is currently in the lib.rs. Once the problem is fixed this will become the lib and the macro exansion can work as intended.

It also exports a connect_ws function which is a helper to construct websocket connection

Basic Example

use holochain_client_core::{
    connect_ws, Future,
};
use url::Url;

fn main() {
    let client_url = Url::parse("ws://localhost:1234").unwrap();
    let client = connect_ws(&client_url).wait().unwrap(); // connect returns a future

    let result = client.zome_call( // calling a function also returns a future
        "instance_id".into(),
        "zome".into(),
        "fn_name".into(),
        serde_json::Value::Null,
    ).wait().unwrap();

    println!("{}", result)
}

Example using different transport (http)

use holochain_client_core::{
    connect_ws, Future, ConductorClient,
}
use jsonrpc_core_client::transports::http;
use url::Url;

fn main() {
    let client_url = Url::parse("http://localhost:1234").unwrap();
    let client = http::connect<ConductorClient>(&client_url).wait().unwrap(); // connect returns a future

    let result = client.zome_call( // calling a function also returns a future
        "instance_id".into(),
        "zome".into(),
        "fn_name".into(),
        serde_json::Value::Null,
    ).wait().unwrap();

    println!("{}", result)
}

Dependencies

~13MB
~242K SLoC