From c367a7034f59f9d66e6c93596c1d56cffee34b4d Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Fri, 12 May 2017 00:04:17 -0400 Subject: [PATCH] Add full example for `Response::json`. --- src/response.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/response.rs b/src/response.rs index bf1c414..ed909e0 100644 --- a/src/response.rs +++ b/src/response.rs @@ -88,6 +88,27 @@ impl Response { } /// Try and deserialize the response body as JSON. + /// + /// # Examples + /// + /// ```rust,no_run + /// extern crate reqwest; + /// #[macro_use] + /// extern crate serde_derive; + /// + /// #[derive(Deserialize)] + /// struct User { + /// name: String, + /// age: u8, + /// } + /// + /// fn main() { + /// let user: User = reqwest::get("http://127.0.0.1/user.json") + /// .expect("network error") + /// .json() + /// .expect("malformed json"); + /// } + /// ``` #[inline] pub fn json(&mut self) -> ::Result { serde_json::from_reader(self).map_err(::error::from)