first release candidate

master
Mathias Rothenhaeusler 2021-09-16 17:04:54 +02:00
parent 540ab15474
commit 0125dfe26c
1 changed files with 4 additions and 11 deletions

View File

@ -1,15 +1,7 @@
use hyper::{Body, Client, Method, Request, Response, body}; use hyper::{Body, Client, Method, Request, body};
use hyper_tls::HttpsConnector; use hyper_tls::HttpsConnector;
use serde::ser; use serde_json::Value;
fn serialize<T>(req: Response<T>) -> serde_json::Result<Response<Vec<u8>>>
where
T: ser::Serialize,
{
let (parts, body) = req.into_parts();
let body = serde_json::to_vec(&body)?;
Ok(Response::from_parts(parts, body))
}
#[tokio::main(flavor = "current_thread")] #[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
let https = HttpsConnector::new(); let https = HttpsConnector::new();
@ -24,6 +16,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let res = client.request(request).await?; let res = client.request(request).await?;
let body_bytes = body::to_bytes(res.into_body()).await?; let body_bytes = body::to_bytes(res.into_body()).await?;
let body = String::from_utf8(body_bytes.to_vec()).expect("response was not valid utf-8"); let body = String::from_utf8(body_bytes.to_vec()).expect("response was not valid utf-8");
println!("Body: {}", body); let v: Value = serde_json::from_str(&body)?;
println!("{}", v["translations"][0]["text"]);
Ok(()) Ok(())
} }