SimonTeixidor / ease

A library for writing REST API clients

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ease - HTTP clients for Rust Build Status

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 is available online and can be built with cargo doc for a local copy.

License

Licensed under either of

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.

About

A library for writing REST API clients

License:MIT License


Languages

Language:Rust 100.0%