Files
reqwest-impersonate/examples/response_json.rs
James Kominick e9d5774365 update example error handling
- Add error-chain dev dependency
- Add error handling using `?` instead of `unwrap`
2017-05-21 16:15:46 -04:00

25 lines
481 B
Rust

//! `cargo run --example response_json`
extern crate reqwest;
#[macro_use] extern crate serde_derive;
#[macro_use] extern crate error_chain;
error_chain! {
foreign_links {
ReqError(reqwest::Error);
}
}
#[derive(Debug, Deserialize)]
struct Response {
origin: String,
}
fn run() -> Result<()> {
let mut res = reqwest::get("https://httpbin.org/ip")?;
let json = res.json::<Response>()?;
println!("JSON: {:?}", json);
Ok(())
}
quick_main!(run);