8 releases

Uses old Rust 2015

0.3.4 Jul 1, 2017
0.3.3 Feb 5, 2016
0.3.0 Jan 31, 2016
0.2.0 Jan 25, 2016
0.1.1 Jan 24, 2016

#1995 in Parser implementations

Download history 32/week @ 2024-02-26 104/week @ 2024-04-01

104 downloads per month

Apache-2.0/MIT

17KB
358 lines

Crest

Build Status

Crest is a REST client library, written in Rust.

Status

It is currently experimental, and incomplete. Pull requests are welcome.

Installation

Crest is available from Cargo. To use it, add this to [dependencies] in Cargo.toml:

crest = "0.3"

Usage

Example: Making a GET request and deserializing the response

The following code first constructs a GET request for a resource at https://httpbin.org/ip, and then deserializes the response – in JSON format – into a custom type.

Note that deserialization is performed by serde; for more information on how to derive Deserialize for custom types, refer to serde documentation.

extern crate crest;
extern crate serde;

use crest::error::Result;
use crest::prelude::*;

#[derive(Debug, Deserialize)]
struct HttpbinIP {
    origin: String,
}

fn example() -> Result<HttpbinIP> {
    // 1. Construct the endpoint off a base URL
    let endpoint = try!(Endpoint::new("https://httpbin.org/"));

    // 2. Construct the request
    let request = try!(endpoint.get(&["ip"]));

    // 3. Perform the request
    let response = try!(request.send());

    // 4. Deserialize the response
    let ip = try!(response.into::<HttpbinIP>());

    Ok(ip)
}

More documentation is available here.

License

Crest is licensed under the Apache License, Version 2.0 (see LICENSE-APACHE) or the MIT license (see LICENSE-MIT), at your option.

Dependencies

~7.5MB
~172K SLoC