Crest is a REST client library, written in Rust.
It is currently experimental, and incomplete. Pull requests are welcome.
Crest is available from Cargo. To use it, add this to
[dependencies]
in Cargo.toml
:
crest = "0.3"
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.
Crest is licensed under the Apache License, Version 2.0 (see LICENSE-APACHE
)
or the MIT license (see LICENSE-MIT
), at your option.