added random quote generator files
This commit is contained in:
parent
7f3d8a0635
commit
0ad9f98721
1114
random_quote/Cargo.lock
generated
Normal file
1114
random_quote/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
13
random_quote/Cargo.toml
Normal file
13
random_quote/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "random_quote"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
json = "0.12.4"
|
||||
serde_json = "1.0.94"
|
||||
reqwest = { version = "0.11", features = ["json", "blocking"] }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
serde = { version = "1.0.130", features = ["derive"] }
|
21
random_quote/src/main.rs
Normal file
21
random_quote/src/main.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use reqwest::blocking::get;
|
||||
|
||||
pub type Response = Vec<Quote>;
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Quote {
|
||||
pub q: String,
|
||||
pub a: String,
|
||||
pub h: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let res = get("https://zenquotes.io/api/random").unwrap();
|
||||
let quotes = res.json::<Response>().unwrap();
|
||||
for quote in quotes {
|
||||
println!("Author: {}", quote.a);
|
||||
println!("Quote: {}", quote.q);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user