Skip to content

Instantly share code, notes, and snippets.

@piedoom
Created June 19, 2018 00:27
Show Gist options
  • Save piedoom/844c1c4f1d8c08b291996e0698c80dc6 to your computer and use it in GitHub Desktop.
Save piedoom/844c1c4f1d8c08b291996e0698c80dc6 to your computer and use it in GitHub Desktop.
/// Send a given request and deserialize the response
pub fn send_and_deserialize(&self, header: OAuthAuthorizationHeader) -> Result<Root, Error> {
let req = self.clone();
// Send the request
let mut response = req
.client
.hyper
.request(req.method, &req.url)
.header(Authorization(header.to_string()))
.send()?;
// Read our response and write to a buffer.
// We can just `unwrap` here since we already error checked.
let mut buf = String::new();
response.read_to_string(&mut buf);
// deserialize from JSON to a `Root` object
serde_json::from_str(&buf)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment