first release candidate
parent
540ab15474
commit
0125dfe26c
15
src/main.rs
15
src/main.rs
|
@ -1,15 +1,7 @@
|
|||
use hyper::{Body, Client, Method, Request, Response, body};
|
||||
use hyper::{Body, Client, Method, Request, body};
|
||||
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")]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let https = HttpsConnector::new();
|
||||
|
@ -24,6 +16,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let res = client.request(request).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");
|
||||
println!("Body: {}", body);
|
||||
let v: Value = serde_json::from_str(&body)?;
|
||||
println!("{}", v["translations"][0]["text"]);
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue