use only one reqwest::Client

This commit is contained in:
blank X 2020-10-27 16:19:37 +07:00
parent c02ad41306
commit 77bf30fada
3 changed files with 7 additions and 5 deletions

2
Cargo.lock generated
View File

@ -1097,7 +1097,7 @@ dependencies = [
[[package]]
name = "rss-anime-notifier-rs"
version = "0.1.0"
version = "0.1.2"
dependencies = [
"chrono",
"reqwest",

View File

@ -1,6 +1,6 @@
[package]
name = "rss-anime-notifier-rs"
version = "0.1.1"
version = "0.1.2"
authors = ["blank X <theblankx@protonmail.com>"]
edition = "2018"

View File

@ -73,9 +73,8 @@ struct AiringSchedule {
pub episode: isize
}
async fn give_response(anime_id: usize) -> Result<impl warp::Reply, Infallible> {
async fn give_response(anime_id: usize, client: Client) -> Result<impl warp::Reply, Infallible> {
let json = json!({"query": QUERY, "variables": {"id": anime_id}});
let client = Client::new();
let resp = match client.post("https://graphql.anilist.co/")
.header("Content-Type", "application/json")
.header("Accept", "application/json")
@ -148,7 +147,10 @@ async fn main() {
Ok(port) => port.parse::<u16>().unwrap(),
Err(_) => 8080
};
let bare_path = warp::path!(usize).and_then(give_response);
let client = Client::new();
let client = warp::any().map(move || client.clone());
let log = warp::log("rss-anime-notifier-rs");
let bare_path = warp::path!(usize).and(client.clone()).and_then(give_response).with(log);
let routes = warp::get().and(bare_path);
eprintln!("INFO: Listening on 127.0.0.1:{}", port);