8 releases

0.0.5 Apr 4, 2023
0.0.4 Mar 24, 2023
0.0.2 Jan 28, 2023

#274 in Web programming

MIT license

195KB
4K SLoC

Nile API Rust Client

This is a POC Rust client for the Nile API.

Usage

Source the Nile environment variables into your environment.

export NILE_DEVELOPER_EMAIL=
export NILE_DEVELOPER_PASSWORD=
export NILE_ENTITY_NAME=
export NILE_ORGANIZATION_NAME=
export NILE_WORKSPACE=
export NILE_INSTANCE_ID=

NILE_URL=https://prod.thenile.dev
use std::env;

use dotenv::dotenv;
use nile_client_rs::{EntityInstance, InstanceUpdate, NileClient};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let username = env::var("NILE_DEVELOPER_EMAIL").expect("NILE_DEVELOPER_EMAIL must be set");
    let password = env::var("NILE_DEVELOPER_PASSWORD").expect("NILE_DEVELOPER_PASSWORD must be set");
    let workspace = env::var("NILE_WORKSPACE").expect("NILE_WORKSPACE must be set");
    let entity_name = env::var("NILE_ENTITY_NAME").expect("NILE_ENTITY_NAME must be set");
    let org = env::var("NILE_ORGANIZATION_NAME").expect("NILE_ORGANIZATION_NAME must be set");


    let mut client = NileClient::default();
    client
        .authenticate(username, password)
        .await?;

List all instances of an entity in a workspace

let instances = client.get_instances(&workspace, &entity_name).await?;
println!("instances: {:#?}", instances);

Poll for all events for an entity in a workspace

let events = client.get_events(&workspace, &entity_name, 0, 20).await?;
println!("events: {:#?}", events);

Update attributes on an existing instance

let mut updates = Vec::new();

// update the number of pods
let pod_ct = InstanceUpdate {
    op: "replace".to_owned(),
    path: "/numPods".to_owned(),
    value: "5".to_owned(),
};
updates.push(pod_ct);

// update database status
let status_update = InstanceUpdate {
    op: "replace".to_owned(),
    path: "/status".to_owned(),
    value: "Up".to_owned(),
};
updates.push(status_update);

// send the updates to the Nile
let status: EntityInstance = client
    .patch_instance(&workspace, &org, &entity_name, &instance_id, updates)
    .await?;
println!("status: {:#?}", status);
}

Dependencies

~6–20MB
~293K SLoC