Connecting to OpenIAP from your application

We provide SDK’s for the following languages:

We recommend using vs.code ( or any other editor based of vscode ) for development, with our openiap-vscode extension, to manage your .env files. To manually generated a jwt token, login to OpenIAP’s web interface app.openiap.io and then go to /jwtlong and copy the jwt field.

To connect to the API and do a queries towards the entities collections, you would do something like this:

  • use openiap_client::{OpenIAPError, Client, QueryRequest};
    async fn main() -> Result<(), OpenIAPError> {
        let client = Client::new_connect("").await?;
        let q = client.query( QueryRequest::with_projection(
            "entities",
            "{}",
            "{\"name\":1}"
        )).await?;
        let items: serde_json::Value = serde_json::from_str(&q.results).unwrap();
        let items: &Vec<serde_json::Value> = items.as_array().unwrap();
        for item in items {
            println!("Item: {:?}", item);
        }
        Ok(())
    }
    
  • const { Client, ClientError } = require('openiap');
    const client = new Client();
    client.connect();
    const query_result = client.query({ collectionname: 'entities', query: '{}', projection: '{"name":1}' });
    console.log("result", query_result);
    client.free();
    
  • from openiap import Client
    client = Client()
    client.connect()
    query_result = client.query(collectionname="entities", query="{}", projection="{\"name\": 1}")
    print("result", query_result)
    client.free()
    
  • static void Main(string[] args) {
        MainAsync(args).GetAwaiter().GetResult();
    }
    static async Task MainAsync(string[] args) {
        Client client = new Client();
        await client.connect();
        string results = await client.Query<string>("entities", "{}", "{\"name\": 1}");
        Console.WriteLine("result: " + results);    
    }
    

For more detailed examples, please see the examples in the respective repositories above.

Building SDK’s from source

please see rust api for source code and most up to date examples.

please see documentation for usage.

openiap-clib also functions as the “backend” for the nodejs, python and dotnet6 SDK’s.

build

make sure you have rust and protobuf installed

  • curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    sudo apt install protobuf-compiler
    cargo install cross --git https://github.com/cross-rs/cross
    sh build.sh
    
  • curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    brew install protobuf
    cargo install cross --git https://github.com/cross-rs/cross
    sh build.sh
    
  • # not tested on windows, but maybe it will work ?
    https://www.rust-lang.org/tools/install
    https://github.com/protocolbuffers/protobuf/releases
    # install cross
    cargo install cross --git https://github.com/cross-rs/cross
    # then run each command inside build.sh
    

Build and run test client

You can run the test client’s from within vs code, remember to add a .env file in the root of the project with the following content:

export jwt=eyJhbGciOiJI...
apiurl=grpc://grpc.app.openiap.io:443

or run the following commands in the terminal:

  • export jwt=eyJhbGciOiJI...
    export apiurl=grpc://grpc.app.openiap.io:443
    cargo run
    
  • export jwt=eyJhbGciOiJI...
    export apiurl=grpc://grpc.app.openiap.io:443
    cd node
    node test.js
    
  • export jwt=eyJhbGciOiJI...
    export apiurl=grpc://grpc.app.openiap.io:443
    cd python
    pip uninstall openiap_edge -y && pip install dist/openiap_edge-0.0.13.tar.gz && python test.py
    
  • export jwt=eyJhbGciOiJI...
    export apiurl=grpc://grpc.app.openiap.io:443
    cd dotnet
    dotnet run
    

Table of contents