Skip to content

Crest is a REST client library, written in Rust

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

pablocouto/crest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Crest is a REST client library, written in Rust

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages