Skip to main content

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!

Be the first to reply!

Reply