Skip to main content

Rust client for Box Platform released

Rust client for Box Platform released
rbarbosa Box

Following up with the Rusty Box: Creating a Rust client for a hackathon, we have released a crate with an initial implementation of the users API end points.


image


You can find the crate here.


You can follow up and participate in this open source project at this GitHub repo.


If you want to try it:


Create a new rust project


cargo new my-box-project

cd my-box-project


Add rusty-box to your dependencies


cargo add dotenv

cargo add rusty-box


Create a .dev.env file in the root of your project


DEVELOPER_TOKEN=YOUR_DEVELOPER_TOKEN


Open your main.rs file and add the following code


use rusty_box::{

    auth::{auth_developer::DeveloperToken, AuthError},

    box_client::BoxClient,

    config::Config,

    rest_api::users::users_api,

};

use std::env;



#[tokio::main]

async fn main() -> Result<(), AuthError> {

    dotenv::from_filename(".dev.env").ok();



    let config = Config::new();

    let auth = DeveloperToken::new(

        config,

        env::var("DEVELOPER_TOKEN").expect("DEVELOPER_TOKEN must be set"),

    );



    let mut client = BoxClient::new(Box::new(auth.clone()));



    let fields = vec![];



    let me = users_api::me(&mut client, Some(fields)).await?;

    println!("Me:\n{me:#?}\n");



    Ok(())

}


Run your project


cargo run


Have fun!

Did this topic help you find an answer to your question?

0 replies

Be the first to reply!

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings