eccool
February 21, 2022, 7:03pm
#1
How can i implement the debug trait for impl Future<Output = Result<_, reqwest::Error>>
let client = Client::new();
let response = client.post(API_URL_INIT_TRANSACTION)
.json(&payload)
.headers(self.construct_headers(true))
.send()
.await.unwrap();
println!("{:?}", response.json());
eccool
February 21, 2022, 7:14pm
#3
I get another error
type inside async fn
body must be known in this context
cannot infer type for type parameter T
declared on the associated function json
alice
February 21, 2022, 7:18pm
#4
If you just want to print the response, use the text()
method instead. The json()
method requires that you specify what type you want to parse the json into.
1 Like
eccool
February 21, 2022, 7:25pm
#5
Awesome, Thanks it works.
But let's say i wanted parse it into a specific type how would i go about doing that, please could you give me an example?
alice
February 21, 2022, 7:54pm
#6
use serde::Deserialize;
#[derive(Deserialize)]
struct MyType {
my_field: String,
}
let body: MyType = response.json().await.unwrap();
or
let body = response.json::<MyType>().await.unwrap();
1 Like
system
closed
May 22, 2022, 7:54pm
#7
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.