Created
April 4, 2020 08:00
-
-
Save fin-ger/5441286805b70f3376c29aa4583ea53c to your computer and use it in GitHub Desktop.
Short example on how to access the github API in rust. Usage: `cargo run <GITHUB_TOKEN>`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "github-api-example" | |
version = "0.1.0" | |
authors = ["Fin Christensen <[email protected]>"] | |
edition = "2018" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
async-std = { version = "1.5.0", features = ["attributes"] } | |
surf = "1.0.3" | |
serde_json = "1.0.48" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const API_URL: &str = "https://api.github.com/repos/deinstapel/cursive-aligned-view/git/commits/8e33b22ea9147fcb04f5532179858d155a7dc931"; | |
#[async_std::main] | |
async fn main() { | |
let github_token = std::env::args().nth(1) | |
.expect("First command line argument should be GitHub Token"); | |
let commit = surf::get(API_URL) | |
.set_header("Authorization", format!("token {}", github_token)) | |
.recv_json::<serde_json::Value>() | |
.await | |
.expect("Commit not found"); | |
println!("{:#?}", commit); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment