withone 0.2.0

Typed Rust client for the One API: the client, webhooks and the action type every withone-<platform> crate builds on.
Documentation

What this crate is

One connects your users' accounts on over a thousand platforms (Gmail, Slack, GitHub, Salesforce and the rest) and lets you call any of their actions through one API, with credentials, token refresh and routing handled for you.

withone is the client: authentication, connections, retries, webhooks and the operation every action runs through. Each platform's typed actions ship as their own crate, withone-<platform>, so you add only the platforms you call.

Install

cargo add withone withone-gmail

The library is imported as one.

Quick start

  1. Create a secret key in the One dashboard and export it as ONE_SECRET.
  2. Connect an account in the dashboard and copy its connection key.
  3. Run an action on that connection:
use one::One;
use withone_gmail as gmail;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let one = One::from_env()?;
    let response = one
        .connection(std::env::var("ONE_CONNECTION_KEY")?)
        .run(gmail::send_users_draft_email().user_id("me").id("r-1234567890"))
        .await?;
    let sent: serde_json::Value = response.json()?;
    println!("{sent:#}");
    Ok(())
}

What the client does

  • Typed actions. Each action takes exactly the fields it needs, required ones enforced when you build, and the client routes each field to the path, query, headers or body.
  • Escape hatches. Turn an action into an operation with into_operation() to merge extra body, query or header fields, set a retry schedule or hook errors.
  • Credentials. One::new takes a secret key, One::builder().access_token(..) acts on a user's OAuth grant, and One::from_env reads ONE_SECRET or ONE_ACCESS_TOKEN.
  • Webhooks. Verify and dispatch One's webhook deliveries with typed handlers per event.

Platforms

Every platform One supports is listed on withone.ai/knowledge, with its actions and how each behaves. Its crate is withone-<platform> on crates.io.

The same client is on npm as @withone/sdk.

License

MIT