4 releases (breaking)

new 0.5.0+20240502.0 May 8, 2024
0.4.0+20240327.0 Apr 2, 2024
0.3.0+0.0.6 Feb 14, 2024
0.2.0 Jan 4, 2024
0.1.0 Aug 28, 2023

#31 in #generated-bindings

Download history 117/week @ 2024-02-09 156/week @ 2024-02-16 52/week @ 2024-02-23 24/week @ 2024-03-01 1/week @ 2024-03-15 97/week @ 2024-03-29 25/week @ 2024-04-05 2/week @ 2024-04-12 83/week @ 2024-05-03

87 downloads per month
Used in oxide-httpmock

MPL-2.0 license

2MB
43K SLoC

The Oxide Rust SDK

Generated bindings for the Oxide API.

Installation

The oxide crate is available on crates.io. You'll probably want to use tokio as well. Add them to your Cargo.toml file or use cargo add:

$ cargo add oxide
$ cargo add tokio

Authentication

To connect to the Oxide API, the SDK needs a host URL and a token. There are two ways to specify these:

  • Environment variables: You can set the OXIDE_HOST and OXIDE_TOKEN environment variables.
  • Configuration file: When you run oxide auth login in the CLI, a $HOME/.config/oxide/hosts.toml file is generated. This file contains sensitive information like your token and user ID.

The SDK will first look for the environment variables, and if they are not defined, it will look for the config file.

Example

Create a new oxide::Client like this:

use futures::StreamExt;
use oxide::{config::Config, context::Context, prelude::*};

#[tokio::main]
async fn main() {
    // Get a client from the on-disk configuration.
    let context = Context::new(Config::default()).expect("unabled to create context");
    let client: &Client = context.client().expect("unable to get client");

    // Start using the client!

    // For example we can look at the projects in our silo:
    let mut projects = client.project_list().stream();
    loop {
        match projects.next().await {
            // No more items.
            None => break,
            // Print the name of a project.
            Some(Ok(project)) => println!("project {}", *project.name),
            // Something went wrong
            Some(Err(err)) => println!("error {}", err),
        }
    }
}

Dependencies

~10–29MB
~442K SLoC