Trait PrettyJson

Source
pub trait PrettyJson<T>: Sized
where T: Serialize + ?Sized,
{ // Required method fn pretty_json(self, json: &T) -> Self; }
Expand description

A trait to set HTTP request body to a “prettified” JSON-formatted representation of the data.

Required Methods§

Source

fn pretty_json(self, json: &T) -> Self

Send a “pretty” JSON body.

Set the HTTP request body to the “pretty” (human-friendly) JSON serialization of the passed value, and also set the Content-Type: application/json header.

use reqwest_pretty_json::PrettyJson;

let mut map = HashMap::new();
map.insert("lang", "rust");

let client = reqwest::Client::new();
let res = client.post("http://httpbin.org")
    .pretty_json(&map)
    .send()
    .await?;
§Errors

Same as reqwest::RequestBuilder::json. See reqwest for more details.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> PrettyJson<T> for RequestBuilder
where T: Serialize + ?Sized,

Source§

fn pretty_json(self, json: &T) -> Self

Source§

impl<T> PrettyJson<T> for RequestBuilder
where T: Serialize + ?Sized,

Source§

fn pretty_json(self, json: &T) -> Self

Implementors§