Skip to content

Commit

Permalink
Update With Clap and first release (I think so)
Browse files Browse the repository at this point in the history
  • Loading branch information
kythonlk committed Feb 14, 2024
1 parent b20384f commit ca41a14
Show file tree
Hide file tree
Showing 7 changed files with 388 additions and 130 deletions.
144 changes: 134 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "rust_http_client"
name = "fastreq"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
clap = { version = "4.5.0", features = ["derive"] }
colored = "2"
Binary file removed fastreq.png
Binary file not shown.
14 changes: 5 additions & 9 deletions src/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,21 @@ pub async fn make_request(
) -> Result<Response, Error> {
let client = Client::new();

let request_builder = match method {
"1" => client.get(url),
"2" => {
let request_builder = match method.to_lowercase().as_str() {
"g" => client.get(url),
"p" => {
let json_body: Value =
serde_json::from_str(body.unwrap_or("{}")).expect("Invalid JSON body");
client.post(url).json(&json_body)
}
"3" => client.put(url).body(body.unwrap_or_default().to_string()),
"4" => client.patch(url).body(body.unwrap_or_default().to_string()),
"put" => client.put(url).body(body.unwrap_or_default().to_string()),
"patch" => client.patch(url).body(body.unwrap_or_default().to_string()),
_ => unimplemented!("This method is not supported"),
};

request_builder.headers(headers).send().await
}

pub fn read_json_file(file_path: &Path) -> std::io::Result<String> {
fs::read_to_string(file_path)
}

pub fn parse_headers(headers_json: &Value) -> Result<HeaderMap, Box<dyn std::error::Error>> {
let mut headers = HeaderMap::new();
if let Value::Object(map) = headers_json {
Expand Down
Loading

0 comments on commit ca41a14

Please sign in to comment.