thats a start

This commit is contained in:
2021-09-16 16:32:45 +02:00
commit 38abdbfa75
4 changed files with 832 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
use hyper::{Body, Client, Method, Request, Response};
use hyper_tls::HttpsConnector;
use serde::ser;
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();
let client = Client::builder().build::<_, hyper::Body>(https);
let request = Request::builder()
.method(Method::POST)
.uri("https://api-free.deepl.com/v2/translate")
.header("content-type", "application/x-www-form-urlencoded")
.body(Body::from(r#"{"library":"hyper"}"#))?;
let res = client.request(request).await?;
println!("{:?}", res.serialize());
assert_eq!(res.status(), 200);
Ok(())
}