catscii/src/main.rs

23 lines
559 B
Rust
Raw Normal View History

2023-05-13 15:38:07 -04:00
use serde::Deserialize;
#[tokio::main]
async fn main() {
2023-05-13 15:15:06 -04:00
let res = reqwest::get("https://api.thecatapi.com/v1/images/search")
.await
.unwrap();
2023-05-13 15:38:07 -04:00
if !res.status().is_success() {
panic!("Request failed with HTTP {}", res.status());
}
#[derive(Deserialize)]
struct CatImage {
url: String,
}
let images: Vec<CatImage> = res.json().await.unwrap();
let image = images
.first()
.expect("the cat API should return at least one image");
println!("The image is at {}", image.url);
}