Crate crest[][src]

Crest is a REST client library built upon Hyper.

Its repository can be found here.

Usage

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.

#[macro_use] extern crate serde_derive;

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 = Endpoint::new("https://httpbin.org/")?;

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

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

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

    Ok(ip)
}

Modules

error

Error and Result types.

prelude

Crest’s prelude.

request

REST requests.

Structs

Endpoint

Handle for working with Requests. This is the main entry point to the library.