Awesome
Ease - HTTP clients for Rust
Ease
is a library for interacting with RESTful APIs.
Examples
In Cargo.toml
, put:
[dependencies]
ease = "*"
Make a GET request and print the result:
extern crate ease;
use ease::{Url, Request};
fn main() {
let url = Url::parse("http://httpbin.org/get").unwrap();
println!("{}", Request::new(url).param("foo", "bar").get().unwrap().body);
}
Make a POST request and deserialize the response from JSON using serde:
#![feature(custom_derive, plugin)]
#![plugin(serde_macros)]
extern crate ease;
use std::collections::HashMap;
use ease::{Url, Request};
#[derive(Deserialize, Debug)]
struct PostResponse {
args: HashMap<String, String>,
data: Option<String>,
files: Option<HashMap<String, String>>,
form: Option<HashMap<String, String>>,
headers: HashMap<String, String>,
json: Option<String>,
origin: String,
url: String,
}
fn main() {
let url = Url::parse("http://httpbin.org/post").unwrap();
println!("{:#?}", Request::new(url).post().and_then(|res| res.from_json::<PostResponse>()));
}
Documentation
Documentation is available online and can be built with cargo doc
for a local copy.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.