Crate reqwest_pretty_json
source ·Expand description
reqwest
provides an easy way of sending JSON-formatted body in the HTTP request and
it always emits terse on-line JSON representation.
Most of the time it is exactly what you need. However, in some cases you may prefer to emit “pretty” JSON representation of your data structures. Key-Value data stores are one such use case and there may be others as well.
In this case you won’t be able to use reqwest::RequestBuilder::json
method and will have to
manually serialize your data and set both the body of the request and Content-Type HTTP header.
This crate provides convenient method to do just that.
It exports trait PrettyJson
that extends reqwest::RequestBuilder
with
PrettyJson::pretty_json
method (in addition to the original
reqwest::RequestBuilder::json
).
This method serializes your data structures as “pretty” JSON
(using serde_json::to_vec_pretty
) and lets reqwest::RequestBuilder::json
do the rest.
use reqwest::Client;
use reqwest_pretty_json::PrettyJson;
let data = vec![1, 2, 3];
let client = Client::new();
let request = client
.post("http://httpbin.org/post")
.pretty_json(&data)
.build();
Traits§
- A trait to set HTTP request body to a “prettified” JSON-formatted representation of the data.