From f106c2c9d23c9c12a88b5a73f704f4be5c455926 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sun, 27 Sep 2020 12:35:24 -0400 Subject: go-stdlib-rust post (#215) --- examples/http_fail.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/http_fail.rs (limited to 'examples/http_fail.rs') diff --git a/examples/http_fail.rs b/examples/http_fail.rs new file mode 100644 index 0000000..98e027a --- /dev/null +++ b/examples/http_fail.rs @@ -0,0 +1,28 @@ +use eyre::Result; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Author { + pub id: i32, + pub name: String, +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Comment { + pub id: i32, + pub author: Author, + pub body: String, + pub in_reply_to: i32, +} + +#[tokio::main] +async fn main() -> Result<()> { + let c: Comment = reqwest::get("https://xena.greedo.xeserv.us/files/comment2.json") + .await? + .error_for_status()? + .json() + .await?; + println!("comment: {:#?}", c); + + Ok(()) +} -- cgit v1.2.3