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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Provides a mockable reqwest-like HTTP client.
//!
//! Write your code generic over the [Client](trait.Client.html) trait,
//! and in production use [DirectClient](struct.DirectClient.html) while in testing
//! you can use [ReplayClient](struct.ReplayClient.html), which will record a request
//! the first time and replay it every time the exact same request is made in the
//! future.
//!
//! # Examples
//!
//! ```
//! use reqwest_mock::{Client, DirectClient, ReplayClient, Error};
//! use reqwest_mock::header::USER_AGENT;
//!
//! struct MyClient<C: Client> {
//!     client: C,
//! }
//!
//! fn new_client() -> MyClient<DirectClient> {
//!     MyClient {
//!         client: DirectClient::new()
//!     }
//! }
//!
//! #[cfg(test)]
//! fn test_client(path: &str) -> MyClient<ReplayClient> {
//!     MyClient {
//!         client: ReplayClient::new(path)
//!     }
//! }
//!
//! impl<C: Client> MyClient<C> {
//!     /// For simplicity's sake we are not parsing the response but just extracting the
//!     /// response body.
//!     /// Also in your own code it might be a good idea to define your own `Error` type.
//!     pub fn get_time(&self) -> Result<String, Error> {
//!         let response = self.client
//!             .get("https://now.httpbin.org/")
//!             .header(USER_AGENT, "MyClient".parse().unwrap())
//!             .send()?;
//!
//!         response.body_to_utf8()
//!     }
//! }
//! ```

extern crate base64;
#[macro_use]
extern crate error_chain;
extern crate http;
#[macro_use]
extern crate log;
extern crate reqwest;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate twox_hash;
extern crate url;

mod helper;

pub mod config;
pub mod error;

mod body;
pub use body::Body;

mod request;
mod response;

pub mod client;
mod request_builder;

pub use self::client::*;
pub use self::error::Error;

pub use reqwest::{header, IntoUrl, Method, StatusCode, Url};
pub use url::ParseError as UrlError;