Crates.io | reqwest_inspect_json |
lib.rs | reqwest_inspect_json |
version | 0.1.0 |
source | src |
created_at | 2021-04-12 10:12:46.389709 |
updated_at | 2022-05-31 09:26:12.872296 |
description | Reqwest extention for json response tracing |
homepage | |
repository | https://github.com/DevNulPavel/reqwest_inspect_json |
max_upload_size | |
id | 382322 |
size | 19,364 |
Provides inspect_json
method for reqwest's response object.
The method is replacement for standart json
method.
Can be usefull for response json-tracing purposes.
ErrorType
must implement both From<reqwest::Error>
+ From<serde_json::Error>
.inspect_json::<ResponseStruct, ErrorType>(move |text| {
debug!("Json data: {}", text);
})
Extended example:
use reqwest_inspect_json::InspectJson;
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
struct TestDataClass {
key1: String,
key2: String,
}
#[derive(Serialize, Deserialize, Debug)]
struct Response {
json: TestDataClass,
}
let test_data = TestDataClass {
key1: "asdada".to_owned(),
key2: "asdagfdgdf".to_owned(),
};
let test_data_copy = test_data.clone();
let client = reqwest::Client::new();
let response = client
.post("http://httpbin.org/post")
.json(&test_data)
.send()
.await
.expect("Request failed")
.inspect_json::<Response, DebugError>(move |text| {
println!("Json content: {}", text);
let text_data = serde_json::from_str::<Response>(text).expect("Parsing failed");
assert_eq!(text_data.json, test_data_copy);
})
.await
.expect("Response parse failed");
assert_eq!(response.json, test_data);