From 4bec70e9a0a2115eb95f631e57ad4f1a0f0cc9dd Mon Sep 17 00:00:00 2001 From: Totoro Date: Tue, 24 Oct 2023 01:07:00 -0400 Subject: [PATCH] 0.0.4 updated the optional inputs, added post support with : matching synax right now. tested against a rust rocket server. --- src/main.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main.rs b/src/main.rs index 2c3db05..3933ff4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,9 @@ struct Args { /// request type #[arg(short, default_value_t = String::new())] get: String, + + #[arg(short)] + json: Option, /// count to run #[arg(short, default_value_t = 1)] count: u8, @@ -25,6 +28,9 @@ fn main() { if args.get.contains("get") || args.get.contains("Get") { let resp = get_req(cmp); println!("{:?}", resp); + } else if args.get.contains("post") || args.get.contains("Post") { + let jsn = args.json.as_deref().unwrap(); + get_post(cmp, String::from(jsn)); } } } @@ -34,6 +40,14 @@ async fn get_req(url: &str) -> Result { Ok(body) } +#[tokio::main] +async fn get_post(url: &str, json: String) { + let spl: Vec<&str> = json.split(":").collect(); + let json_data = format!(r#"{{"{}": "{}"}}"#, spl[0], spl[1]); + let client = reqwest::Client::new(); + + println!("{:?}", json_data); +} //add post support with json //transfer 25 into a fn //update the instruction on usage