Created
September 22, 2020 07:49
-
-
Save cuongld2/3b04d83e4ccaddea03cad2b469cbeeff to your computer and use it in GitHub Desktop.
simple http request
This file contains 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
use serde::Deserialize; | |
use reqwest::Error; | |
#[derive(Deserialize, Debug)] | |
struct User { | |
login: String, | |
id: u32, | |
} | |
#[tokio::main] | |
async fn main() -> Result<(), Error> { | |
let request_url = format!("https://api.github.com/repos/{owner}/{repo}/stargazers", | |
owner = "rust-lang-nursery", | |
repo = "rust-cookbook"); | |
println!("{}", request_url); | |
let response = reqwest::get(&request_url).await?; | |
let users: Vec<User> = response.json().await?; | |
println!("{:?}", users); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment