add the ability to deserialize JSON from a response body directly
This commit is contained in:
@@ -7,7 +7,7 @@ use hyper::status::StatusCode;
|
||||
use hyper::version::HttpVersion;
|
||||
use hyper::{Url};
|
||||
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json;
|
||||
use serde_urlencoded;
|
||||
|
||||
@@ -275,6 +275,11 @@ impl Response {
|
||||
pub fn version(&self) -> &HttpVersion {
|
||||
&self.inner.version
|
||||
}
|
||||
|
||||
/// Try and deserialize the response body as JSON.
|
||||
pub fn json<T: Deserialize>(&mut self) -> ::Result<T> {
|
||||
serde_json::from_reader(self).map_err(::Error::from)
|
||||
}
|
||||
}
|
||||
|
||||
/// Read the body of the Response.
|
||||
|
||||
Reference in New Issue
Block a user