Skip to content

Commit

Permalink
Parses response into json, not yet usable
Browse files Browse the repository at this point in the history
  • Loading branch information
holtkampjs committed Mar 11, 2023
1 parent 83a9f99 commit edd335d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 77 deletions.
85 changes: 16 additions & 69 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ edition = "2021"

[dependencies]
reqwest = { version = "0.11", features = ["blocking", "json", "gzip"] }
tokio = { version = "1.15", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
18 changes: 11 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use reqwest::Result;
#![allow(unused)]

#[tokio::main]
async fn main() -> Result<()> {
struct WordOfTheDay {
word: String,
category: String,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("WORDNIK_API_KEY").unwrap();
let url = "https://api.wordnik.com/v4/words.json/randomWord?api_key=".to_owned() + &api_key;
let response = reqwest::get(url).await?;
let body = response.text().await?;
println!("{}", body);
let url = "https://api.wordnik.com/v4/words.json/wordOfTheDay?api_key=".to_owned() + &api_key;
let response = reqwest::blocking::get(url)?.text()?;
let json: serde_json::Value = serde_json::from_str(&response)?;
println!("{:#?}", json);
Ok(())
}

0 comments on commit edd335d

Please sign in to comment.