sagebind / isahc

The practical HTTP client that is fun to use.

Home Page:https://docs.rs/isahc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

is any plan add json_pretty method ?

baoyachi opened this issue · comments

json

       let json = Request::post(url)
        .header("Content-Type", "application/json")
        .timeout(Duration::from_secs(timeout))
        .body(body)?
        .send()?
        .json::<serde_json::Value>()?;

Serialize the given data structure as a pretty-printed String of JSON.

like this:

       let json = Request::post(url)
        .header("Content-Type", "application/json")
        .timeout(Duration::from_secs(timeout))
        .body(body)?
        .send()?
        .json_pretty:<serde_json::Value>()?;

I'm not sure I understand what is being proposed here. In this example, the json method is de-serializing the response body from the server into the desired type, so a json_pretty here wouldn't make sense since one method can de-serialize both pretty and compact JSON equivalently.

Isahc doesn't provide any convenience methods right now for serializing the request body, but you can probably use to_vec_pretty from serde_json to do that.