use color_eyre::eyre::Result;
pub async fn main_server_request(
host: Option<&String>,
port: Option<u16>,
url_path: &str,
) -> Result<String> {
let url_string = make_main_server_url(host, port, url_path);
println!("main_server_request() request: {url_string}");
let response: reqwest::Response = reqwest::Client::builder()
.build()?
.get(&url_string)
.header("Accept", "application/json")
.send()
.await?;
let body = response.text().await?;
Ok(body)
}
pub fn make_main_server_url(host: Option<&String>, port: Option<u16>, url_path: &str) -> String {
let default_host = crate::web::LOCALHOST_STR.to_string();
let host = host.unwrap_or(&default_host);
let port = port.unwrap_or(crate::web::SERVER_PORTS_MAIN_PORT);
format!("http://{host}:{port}{url_path}")
}