Expand description
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")) }
}
#[tokio::main(flavor = "current_thread")]
async 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 = client.get::<_, HttpBinAnything>(()).await.unwrap().into_inner();
println!("{:?}", data);
}
Modules
- Blocking variant of the
RestClient
Structs
- Builder for
RestClient
- Type returned by client query functions
- REST client to make HTTP GET and POST requests.
Enums
- Restson error return type.
Traits
- Rest path builder trait for type.
Type Definitions
- Type for URL query parameters.