cartographer/src/main.rs

41 lines
1,015 B
Rust
Raw Normal View History

2024-09-11 01:34:47 -07:00
use reqwest::header;
use reqwest::{Client, Error};
2024-09-11 01:34:47 -07:00
use std::env;
static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);
fn create_client() -> Result<Client, Error> {
let token =
env::var("CANVAS_SECRET").expect("Canvas API key is not defined in the environment.");
2024-09-11 01:34:47 -07:00
let mut headers = header::HeaderMap::new();
headers.insert(
header::AUTHORIZATION,
format!("Bearer {}", token).parse().unwrap(),
2024-09-11 01:34:47 -07:00
);
reqwest::Client::builder()
2024-09-11 01:34:47 -07:00
.user_agent(APP_USER_AGENT)
.default_headers(headers)
.build()
}
2024-09-11 01:34:47 -07:00
async fn get_request() -> Result<(), reqwest::Error> {
let response = create_client()?
2024-09-11 01:34:47 -07:00
.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(())
}