From 1a9a3ecf18cd71898be230e2045b2d907f8fcdd7 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 29 May 2021 14:39:29 +0200 Subject: Parse GitHub API response to a struct --- src/main.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 5edbf17..14d5f4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use reqwest::blocking::ClientBuilder; +use serde::Deserialize; const USER_AGENT: &'static str = concat!( @@ -8,6 +9,18 @@ const USER_AGENT: &'static str = concat!( ); +#[derive(Debug, Deserialize)] +struct Repo { + id: usize, + name: String, + description: Option, + fork: bool, + git_url: String, + default_branch: String, + updated_at: String, // TODO: Maybe parse to date? +} + + fn main() { let mut headers = reqwest::header::HeaderMap::new(); headers.insert("Accept", "application/vnd.github.v3+json".parse().unwrap()); @@ -26,6 +39,8 @@ fn main() { ), ) .send() + .unwrap() + .json::>() .unwrap(); dbg!(&response); -- cgit v1.2.3