diff --git a/backend/src/main.rs b/backend/src/main.rs index f829c96..08b6c2e 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -2,14 +2,31 @@ use axum::{response::IntoResponse, routing::get, Json, Router}; use axum_extra::routing::SpaRouter; use clap::Parser; use serde::{Deserialize, Serialize}; +use std::collections::HashMap; use std::net::{IpAddr, Ipv6Addr, SocketAddr}; use std::str::FromStr; use tower::ServiceBuilder; use tower_http::trace::TraceLayer; +#[derive(Deserialize, Serialize, Debug)] +struct Docs { + key: String, + title: String, + first_publish_year: Option, + number_of_pages_median: Option, + isbn: Option>, + cover_i: Option, + author_name: Option>, + person: Option>, + place: Option>, + subject: Option>, + time: Option>, +} + #[derive(Deserialize, Serialize, Debug)] struct Books { num_found: u32, + docs: Vec, } // Setup the command line interface with clap. @@ -62,12 +79,31 @@ async fn main() { .expect("Unable to start server"); } -async fn hello() -> impl IntoResponse { +async fn hello( + axum::extract::Query(params): axum::extract::Query>, +) -> impl IntoResponse { //"hello from server!" - let res = reqwest::get("https://openlibrary.org/search.json?q=the+lord+of+the+rings") - .await - .expect("Unable to request"); + //let res = reqwest::get("https://openlibrary.org/search.json?q=the+lord+of+the+rings") + // .await + // .expect("Unable to request"); + //let resjson = res.json::().await.expect("Unable to return value"); + print!("Get items with query params: {:?}\n", params); + //let search = params.get("search"); + //let search = ""; + let search = params.get("search").unwrap(); + //match search { + // Some(token) => (), + // None => return "None", + //} + //let search = match params.get("search") { + // Some(&token) => token, + // _ => String(""), + //}; + let query = format!("https://openlibrary.org/search.json?q={}", search); + let res = reqwest::get(query).await.expect("Unable to request"); let resjson = res.json::().await.expect("Unable to return value"); + print!("Search token {:?}\n", search); return Json(resjson); + //return "Hello"; }