[][src]Crate restson

Easy-to-use REST client for Rust programming language that provides automatic serialization and deserialization from Rust structs. The library is implemented using Hyper and Serde JSON.

Examples

extern crate restson;
#[macro_use]
extern crate serde_derive;

use restson::{RestClient,RestPath,Error};

// Data structure that matches with REST API JSON
#[derive(Serialize,Deserialize,Debug)]
struct HttpBinAnything {
    method: String,
    url: String,
}

// Path of the REST endpoint: e.g. http://<baseurl>/anything
impl RestPath<()> for HttpBinAnything {
    fn get_path(_: ()) -> Result<String,Error> { Ok(String::from("anything")) }
}

fn main() {
    // Create new client with API base URL
    let mut client = RestClient::new("http://httpbin.org").unwrap();

    // GET http://httpbin.org/anything and deserialize the result automatically
    let data: HttpBinAnything = client.get(()).unwrap();
    println!("{:?}", data);
}

Structs

Builder

Builder for RestClient

RestClient

REST client to make HTTP GET and POST requests.

Enums

Error

Restson error return type.

Traits

RestPath

Rest path builder trait for type.

Type Definitions

HyperClient
Query

Type for URL query parameters.