move lib, server and client to separate packages

This commit is contained in:
Johannes Heuel
2022-09-14 12:38:11 +02:00
parent 32f92b9320
commit 6e925b731e
10 changed files with 590 additions and 39 deletions

View File

@@ -0,0 +1,66 @@
use core::time::Duration;
use reqwest::blocking::Client;
use reqwest::header;
use zoidberg_lib::types::Update;
fn build_client(secret: &str) -> Client {
let cookie = format!("secret={}", secret);
let mut headers = header::HeaderMap::new();
headers.insert(
"cookie",
header::HeaderValue::from_str(&cookie)
.unwrap_or_else(|_| panic!("invalid header value {}", &cookie)),
);
Client::builder()
.default_headers(headers)
.timeout(Duration::from_secs(15))
.build()
.expect("Could not create HTTP client")
}
fn main() {
// test get request to index
let res = build_client("some_secret")
.get("http://localhost:8080/")
.send()
.expect("Could not send get request");
println!("Status: {}", res.status());
println!("Headers:\n{:#?}", res.headers());
let body = res.text().unwrap();
println!("Body:\n{}", body);
(0..10).for_each(|_| {
// test get request to /register
let res = build_client("some_secret")
.get("http://localhost:8080/register")
.send()
.expect("Could not send get request");
println!("Status: {}", res.status());
println!("Headers:\n{:#?}", res.headers());
let body = res.text().unwrap();
println!("Body:\n{}", body);
});
// test post request to /update
let update = Update {
id: 99,
status: "hi".to_string(),
};
let res = build_client("some_secret")
.post("http://localhost:8080/update")
.json(&update)
.send()
.expect("Could not send get request");
println!("Status: {}", res.status());
println!("Headers:\n{:#?}", res.headers());
let body = res.text().unwrap();
println!("Body:\n{}", body);
}