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
- Blocking variant of the
RestClient
Structs§
- Builder
- Builder for
RestClient
- Response
- Type returned by client query functions
- Rest
Client - REST client to make HTTP GET and POST requests.
Enums§
- Error
- Restson error return type.
Traits§
- Rest
Path - Rest path builder trait for type.
Type Aliases§
- Hyper
Client - Query
- Type for URL query parameters.