This commit is contained in:
2022-10-02 10:05:37 +05:30
parent 4c81efcd6d
commit 3db883225b

View File

@@ -1,11 +1,17 @@
use axum::{response::IntoResponse, routing::get, Router}; 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 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 Books {
numFound: u32,
}
// Setup the command line interface with clap. // Setup the command line interface with clap.
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[clap(name = "server", about = "A server for our wasm project!")] #[clap(name = "server", about = "A server for our wasm project!")]
@@ -57,5 +63,8 @@ async fn main() {
} }
async fn hello() -> impl IntoResponse { async fn hello() -> impl IntoResponse {
"hello from server!" //"hello from server!"
let res = reqwest::get("https://openlibrary.org/search.json?q=the+lord+of+the+rings").await?;
let resjson = res.json::<Books>().await;
return Json(resjson);
} }