Skip to content

Commit ca41a14

Browse files
committed
Update With Clap and first release (I think so)
1 parent b20384f commit ca41a14

File tree

7 files changed

+388
-130
lines changed

7 files changed

+388
-130
lines changed

Cargo.lock

Lines changed: 134 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
2-
name = "rust_http_client"
2+
name = "fastreq"
33
version = "0.1.0"
44
edition = "2021"
55

6-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7-
86
[dependencies]
97

108
reqwest = { version = "0.11", features = ["json"] }
119
tokio = { version = "1", features = ["full"] }
1210
serde = { version = "1.0", features = ["derive"] }
1311
serde_json = "1.0"
12+
clap = { version = "4.5.0", features = ["derive"] }
13+
colored = "2"

fastreq.png

-67.2 KB
Binary file not shown.

src/api_client.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,21 @@ pub async fn make_request(
2020
) -> Result<Response, Error> {
2121
let client = Client::new();
2222

23-
let request_builder = match method {
24-
"1" => client.get(url),
25-
"2" => {
23+
let request_builder = match method.to_lowercase().as_str() {
24+
"g" => client.get(url),
25+
"p" => {
2626
let json_body: Value =
2727
serde_json::from_str(body.unwrap_or("{}")).expect("Invalid JSON body");
2828
client.post(url).json(&json_body)
2929
}
30-
"3" => client.put(url).body(body.unwrap_or_default().to_string()),
31-
"4" => client.patch(url).body(body.unwrap_or_default().to_string()),
30+
"put" => client.put(url).body(body.unwrap_or_default().to_string()),
31+
"patch" => client.patch(url).body(body.unwrap_or_default().to_string()),
3232
_ => unimplemented!("This method is not supported"),
3333
};
3434

3535
request_builder.headers(headers).send().await
3636
}
3737

38-
pub fn read_json_file(file_path: &Path) -> std::io::Result<String> {
39-
fs::read_to_string(file_path)
40-
}
41-
4238
pub fn parse_headers(headers_json: &Value) -> Result<HeaderMap, Box<dyn std::error::Error>> {
4339
let mut headers = HeaderMap::new();
4440
if let Value::Object(map) = headers_json {

0 commit comments

Comments
 (0)