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