1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! requests - HTTP client library with simple API.\
//! If you have used Python requests module you will find the API familiar.
//!
//! # Quick Start
//!
//! ```rust
//! extern crate requests;
//! use requests::ToJson;
//!
//! fn main() {
//!     let response = requests::get("http://httpbin.org/get").unwrap();
//!     assert_eq!(response.url(), "http://httpbin.org/get");
//!     assert_eq!(response.reason(), "OK");
//!     assert_eq!(response.status_code(), requests::StatusCode::Ok);
//!
//!     let data = response.json().unwrap();
//!     assert_eq!(data["url"], "http://httpbin.org/get");
//!     assert_eq!(data["headers"]["Host"], "httpbin.org");
//!     assert_eq!(data["headers"]["User-Agent"],
//!                concat!("requests-rs/", env!("CARGO_PKG_VERSION")));
//! }
//! ```

extern crate hyper;
#[cfg(feature = "ssl")]
extern crate hyper_native_tls;
#[cfg(feature = "with_json")]
extern crate json;

mod request;
mod response;
mod tojson;

pub use request::Request;
pub use response::Response;
pub use response::{Codes, StatusCode};
pub use tojson::ToJson;

pub type Result = hyper::Result<Response>;
pub type Error = hyper::error::Error;

pub fn get<T: AsRef<str>>(url: T) -> Result {
    Request::default().get(url.as_ref())
}

pub fn post<T: AsRef<str>>(url: T) -> Result {
    Request::default().post(url.as_ref())
}

pub fn put<T: AsRef<str>>(url: T) -> Result {
    Request::default().put(url.as_ref())
}

pub fn head<T: AsRef<str>>(url: T) -> Result {
    Request::default().head(url.as_ref())
}

pub fn delete<T: AsRef<str>>(url: T) -> Result {
    Request::default().delete(url.as_ref())
}