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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
//! # rttp
//! A simple to use http lib for rust.
//!
//! # rttp_client
//!
//! ## Additional features
//! rttp_client is a minimal http client, the default features only support
//! http request, but you can add features to support https request, and async support
//!
//! | name | comment |
//! |------|---------|
//! | async | Async request features |
//! | tls-native | support https request use `native-tls` crate |
//! | tls-rustls | support https request use `rustls` crate |
//!
//! The default use
//!
//! ```toml
//! [dependencies]
//! rttp_client = "*"
//! ```
//!
//! With tls-native
//!
//! ```toml
//! [dependencies]
//! rttp_client = { version = "*", features = ["tls-native"] }
//! ```
//!
//! With tls-rustls
//!
//! ```toml
//! [dependencies]
//! rttp_client = { version = "*", features = ["tls-rustls"] }
//! ```
//!
//! Async support
//!
//!
//! ```toml
//! [dependencies]
//! rttp_client = { version = "*", features = ["async"] }
//! ```
//!
//! Full support
//!
//! ```toml
//! [dependencies]
//! rttp_client = { version = "*", features = ["async", "tls-native"] }
//! ```
//!
//! *Important*
//! `tls-native` and `tls-rustls` only support choose on features, do not same to use.
//!
//! ## Examples
//!
//! ### GET
//!
//! ```rust
//! # use rttp_client::HttpClient;
//! HttpClient::new().get()
//!   .url("http://httpbin.org/get")
//!   .emit();
//! ```
//!
//! ### POST
//!
//! ```rust
//! # use rttp_client::HttpClient;
//! HttpClient::new().post()
//!   .url("http://httpbin.org/post")
//!   .emit();
//! ```
//!
//! ### Header
//!
//! ```rust
//! # use rttp_client::HttpClient;
//! # use rttp_client::types::Header;
//! # use std::collections::HashMap;
//! let mut multi_headers = HashMap::new();
//! multi_headers.insert("name", "value");
//! HttpClient::new().get()
//!  .url("http://httpbin.org/get")
//!  .header("name=value&name=value")
//!  .header(("name", "value", "name=value&name=value"))
//!  .header(Header::new("name", "value"))
//!  .header(multi_headers)
//!  .emit();
//! ```
//!
//! ### Para
//!
//! ```rust
//! # use rttp_client::HttpClient;
//! # use rttp_client::types::Para;
//! # use std::collections::HashMap;
//! let mut multi_para = HashMap::new();
//! multi_para.insert("name", "value");
//! HttpClient::new().post()
//!   .url("http://httpbin.org/post")
//!   .para("name=value&name=value")
//!   .para(("name", "value", "name=value&name=value"))
//!   .para(Para::new("name", "value"))
//!   .para(multi_para)
//!   .emit();
//! ```
//!
//! ### Url
//!
//! ```rust
//! # use rttp_client::HttpClient;
//! # use rttp_client::types::RoUrl;
//! HttpClient::new().get()
//!   .url(RoUrl::with("http://httpbin.org").path("get").para("name=value").para(("from", "rttp")))
//!   .emit();
//! ```
//!
//! ### POST JSON
//!
//! ```rust
//! # use rttp_client::HttpClient;
//! HttpClient::new().post()
//!   .url("http://httpbin.org/post")
//!   .content_type("application/json")
//!   .raw(r#" {"id": 1, "from": "rttp"} "#)
//!   .emit();
//! ```
//!
//! ### Form && Upload file
//!
//! ```rust
//! # use rttp_client::HttpClient;
//! # use rttp_client::types::FormData;
//! # use std::collections::HashMap;
//! let mut multi_form = HashMap::new();
//! multi_form.insert("name", "value");
//! HttpClient::new().post()
//!   .url("http://httpbin.org/post")
//!   .para("name=value")
//!   .form("name=value")
//!   .form("name=value&name=value")
//!   .form(("name", "value", "name=value&name=value"))
//!   .form("file=@filename#/path/to/file")
//!   .form("file=@/path/to/file")
//!   .form(multi_form)
//!   .form(FormData::with_text("name", "value"))
//!   .form(FormData::with_file("name", "/path/to/file"))
//!   .form(FormData::with_file_and_name("name", "/path/to/file", "filename"))
//!   .form(FormData::with_binary("name", vec![]))  // Vec<u8>
//!   .emit();
//! ```
//! Para and form can be mixed, para does not support file parsing
//!
//! ### Proxy
//!
//! *BASIC*
//!
//! ```rust
//! # use rttp_client::HttpClient;
//! # use rttp_client::types::Proxy;
//! HttpClient::new().post()
//!   .url("http://httpbin.org/post")
//!   .content_type("application/json")
//!   .raw(r#" {"id": 1, "from": "rttp"} "#)
//!   .proxy(Proxy::http("127.0.0.1", 1081))
//!   .emit();
//! ```
//!
//! *BASIC WITH AUTHORIZATION*
//!
//! ```rust
//! # use rttp_client::HttpClient;
//! # use rttp_client::types::Proxy;
//! HttpClient::new().post()
//!   .url("http://httpbin.org/post")
//!   .content_type("application/json")
//!   .raw(r#" {"id": 1, "from": "rttp"} "#)
//!   .proxy(Proxy::socks5_with_authorization("127.0.0.1", 1081, "username", "password"))
//!   .emit();
//! ```
//!
//! ### Auto redirect
//!
//! ```rust
//! # use rttp_client::HttpClient;
//! # use rttp_client::Config;
//! let response = HttpClient::new().post()
//!   .config(Config::builder().auto_redirect(true))
//!   .get()
//!   .url("http://bing.com")
//!   .emit();
//! assert!(response.is_ok());
//! let response = response.unwrap();
//! assert_ne!("bing.com", response.host());
//! ```
//!
//! ### Async
//!
//! ```rust
//! # use rttp_client::HttpClient;
//! # #[cfg(feature = "async")]
//! # async fn test_async() {
//! let response = HttpClient::new().post()
//!   .url("http://httpbin.org/post")
//!   .rasync()
//!   .await;
//! # }
//! ```
//!
//!
//!
//!

pub use self::client::*;
pub use self::config::*;

mod client;
mod request;
mod connection;
mod config;

pub mod types;
pub mod error;
pub mod response;