The SDKs are under development. New releases may contain breaking changes.
Authentication
To use any of the SDKs, you’ll need a host URL and a device token. The easiest way to get a token is through the CLI. First, log in:
$ oxide auth login --host https://my-oxide-rack.comThen print the token:
$ oxide auth status --show-tokenSee the Authentication guide for more details.
Rust
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 tokioUsage
To connect to the Oxide API, the SDK needs a host URL and a token. There are several ways to specify these:
Configuration files: the CLI’s
oxide auth logincommand generatesconfig.tomlandcredentials.tomlin$HOME/. The credentials file contains sensitive information such as tokens and user IDs..config/ oxide/ Environment variables: You can set the
OXIDE_HOSTandOXIDE_TOKENenvironment variables.Explicit host URL and token.
The simplest way to create an authenticated client is to use
oxide::Client::new_authenticated(), which uses the same credentials and
authentication logic as the CLI. By default, it reads data from configuration
files in $HOME/.
use futures::StreamExt;
use oxide::{Client, prelude::*};
#[tokio::main]
async fn main() {
// Make a client from the on-disk configuration.
let client = Client::new_authenticated()
.expect("unable to create an authenticated 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),
}
}
}TypeScript
@oxide/api is built on the Fetch API and has no dependencies. It works in the browser, Node.js 18+, Deno, Bun, or any other runtime that supports Fetch.
Installation
$ npm install @oxide/apiUsage
import Oxide from "@oxide/api"
const oxide = new Oxide({
host: "https://my-oxide-rack.com",
token: "oxide-abc123",
})
const result = await oxide.methods.projectList({})
if (result.type === "success") {
console.log(result.data.items.map((p) => p.name))
}Go
Installation
Use go get inside your module dependencies directory to install the SDK:
$ go get github.com/oxidecomputer/oxide.go@latestUsage
package main
import (
"context"
"fmt"
"github.com/oxidecomputer/oxide.go/oxide"
)
func main() {
client, err := oxide.NewClient(
oxide.WithHost("https://api.oxide.computer"),
oxide.WithToken("oxide-abc123"),
)
if err != nil {
panic(err)
}
ctx := context.Background()
params := oxide.ProjectCreateParams{
Body: &oxide.ProjectCreate{
Description: "A sample project",
Name: oxide.Name("my-project"),
},
}
resp, err := client.ProjectCreate(ctx, params)
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", resp)
}