v0.02
This commit is contained in:
@@ -2,14 +2,31 @@ use axum::{response::IntoResponse, routing::get, Json, Router};
|
|||||||
use axum_extra::routing::SpaRouter;
|
use axum_extra::routing::SpaRouter;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::net::{IpAddr, Ipv6Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv6Addr, SocketAddr};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use tower::ServiceBuilder;
|
use tower::ServiceBuilder;
|
||||||
use tower_http::trace::TraceLayer;
|
use tower_http::trace::TraceLayer;
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
|
struct Docs {
|
||||||
|
key: String,
|
||||||
|
title: String,
|
||||||
|
first_publish_year: Option<u32>,
|
||||||
|
number_of_pages_median: Option<u32>,
|
||||||
|
isbn: Option<Vec<String>>,
|
||||||
|
cover_i: Option<u32>,
|
||||||
|
author_name: Option<Vec<String>>,
|
||||||
|
person: Option<Vec<String>>,
|
||||||
|
place: Option<Vec<String>>,
|
||||||
|
subject: Option<Vec<String>>,
|
||||||
|
time: Option<Vec<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
struct Books {
|
struct Books {
|
||||||
num_found: u32,
|
num_found: u32,
|
||||||
|
docs: Vec<Docs>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the command line interface with clap.
|
// Setup the command line interface with clap.
|
||||||
@@ -62,12 +79,31 @@ async fn main() {
|
|||||||
.expect("Unable to start server");
|
.expect("Unable to start server");
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn hello() -> impl IntoResponse {
|
async fn hello(
|
||||||
|
axum::extract::Query(params): axum::extract::Query<HashMap<String, String>>,
|
||||||
|
) -> impl IntoResponse {
|
||||||
//"hello from server!"
|
//"hello from server!"
|
||||||
let res = reqwest::get("https://openlibrary.org/search.json?q=the+lord+of+the+rings")
|
//let res = reqwest::get("https://openlibrary.org/search.json?q=the+lord+of+the+rings")
|
||||||
.await
|
// .await
|
||||||
.expect("Unable to request");
|
// .expect("Unable to request");
|
||||||
|
//let resjson = res.json::<Books>().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::<Books>().await.expect("Unable to return value");
|
let resjson = res.json::<Books>().await.expect("Unable to return value");
|
||||||
|
|
||||||
|
print!("Search token {:?}\n", search);
|
||||||
return Json(resjson);
|
return Json(resjson);
|
||||||
|
//return "Hello";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user