use reqwest::header; use reqwest::{Client, Error}; use std::env; static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),); fn create_client() -> Result { let token = env::var("CANVAS_SECRET").expect("Canvas API key is not defined in the environment."); let mut headers = header::HeaderMap::new(); headers.insert( header::AUTHORIZATION, format!("Bearer {}", token).parse().unwrap(), ); reqwest::Client::builder() .user_agent(APP_USER_AGENT) .default_headers(headers) .build() } async fn get_request() -> Result<(), reqwest::Error> { let response = create_client()? .get("https://ucsb.instructure.com/api/v1/courses") .send() .await?; println!("Status: {}", response.status()); let body = response.text().await?; println!("Body:\n{}", body); Ok(()) } #[tokio::main] async fn main() -> Result<(), Error> { get_request().await?; Ok(()) }