Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

NOTE: Author here - this library is now really out of date, and does not compile anymore. Please don't try to build anything new on top of it.

It won't be updated until I find some time to dig into Rust again and get up to speed with the latest version of the language.

Rust REST Client

A simple HTTP and REST client for Rust, inspired by Ruby's rest-client.

The goal: make common REST requests with the fewest lines of code.

Built on top of the Hyper HTTP library.

Full API Documentation


First, add the dependency to your Cargo.toml:


git = ""

Then, cargo update, write your code, cargo build, cargo run, etc.

extern crate rest_client;
extern crate rustc_serialize;

// One simple 'use' to get all the functionality, plus the 'extern crate'.
use rest_client::RestClient;
use rustc_serialize::json;

fn main() {
    // A simple GET is just a GET. You can print the response struct (it supports Show).
    println!("{}", RestClient::get("").unwrap());
    // You can use an array of tuples to create a GET with query parameters.
    // The client handles all the URL-encoding and escaping for you.
    println!("{}", RestClient::get_with_params("",
                                               &[("id", "50"), ("foo", "bar")]).unwrap());

    // You can also use an array of tuples to create a POST with form parameters. 
    // The client sets the content-type to application/x-www-form-urlencoded for you.
    println!("{}", RestClient::post_with_params("",
                                                &[("param1", "one"), 
                                                  ("param2", "two")]).unwrap());

    // You can POST a string or a JSON object with just a string and a MIME type.
    let object = TestStruct {
        data_int: 1,
        data_str: "toto".to_string(),
        data_vector: vec![2,3,4,5],
    println!("{}", RestClient::post("",

    // PUT and PATCH are supported as well, just like POST.
    // You can delete a resource with a simple DELETE. delete_with_params works too.
    println!("{}", RestClient::delete("").unwrap());
      The response struct has a few fields
      code (a simple integer)
      body (a string)
      status (a typed response code, from Hyper)
      headers (typed headers from Hyper)
    let response = RestClient::get("").unwrap();
    println!("{}", response.code); // -> 404
    for header in response.headers.iter() {
        println!("{}", header); // -> (Cache-Control, max-age=604800) ...
    println!("{}", response.to_string());				  
      All of the underlying errors are passed up through 
      the RestError struct in the Result.
      pub enum RestError {

#[deriving(Decodable, Encodable)]
pub struct TestStruct  {
    data_int: u8,
    data_str: String,
    data_vector: Vec<u8>,


    println!("{}", RestClient::get("").unwrap());

    let response = RestClient::get("").unwrap();
    let response_json = Json::from_str(&response.body).unwrap();

    println!("{}", response_json.as_object().unwrap()

    println!("{}", RestClient::post_with_params("", 
                                                &[("api_type", "json"),
                                                  ("user", "myusername"),
                                                  ("passwd", "mypassword"),
                                                  ("rem", "True")]).unwrap());


  • Add support for custom request headers
  • Built-in JSON serialization?
  • Examine what parts of Hyper should get re-exposed
  • Add support for cookies
  • Extend hyper to support basic auth (lots of APIs need it)
  • Multipart POST
  • Unit tests
  • Testing in real applications
  • Refactoring


A simple HTTP and REST client for Rust, inspired by Ruby's rest-client.




No releases published


No packages published


You can’t perform that action at this time.