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 = "0.1"
With tls-native
toml
[dependencies]
rttp_client = { version = "0.1", features = ["tls-native"] }
With tls-rustls
toml
[dependencies]
rttp_client = { version = "0.1", features = ["tls-rustls"] }
Async support
toml
[dependencies]
rttp_client = { version = "0.1", features = ["async"] }
Full support
toml
[dependencies]
rttp_client = { version = "0.1", features = ["async", "tls-native"] }
Important
tls-native
and tls-rustls
only support choose on features, do not same to use.
```rust
HttpClient::new().get() .url("http://httpbin.org/get") .emit(); ```
```rust
HttpClient::new().post() .url("http://httpbin.org/post") .emit(); ```
```rust
let mut multiheaders = HashMap::new(); multiheaders.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(); ```
```rust
let mut multipara = HashMap::new(); multipara.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(); ```
```rust
HttpClient::new().get() .url(RoUrl::with("http://httpbin.org").path("get").para("name=value").para(("from", "rttp"))) .emit(); ```
```rust
HttpClient::new().post() .url("http://httpbin.org/post") .content_type("application/json") .raw(r#" {"id": 1, "from": "rttp"} "#) .emit(); ```
```rust
let mut multiform = HashMap::new();
multiform.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(multiform)
.form(FormData::withtext("name", "value"))
.form(FormData::withfile("name", "/path/to/file"))
.form(FormData::withfileandname("name", "/path/to/file", "filename"))
.form(FormData::with_binary("name", vec![])) // Vec
BASIC
```rust
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
HttpClient::new().post() .url("http://httpbin.org/post") .contenttype("application/json") .raw(r#" {"id": 1, "from": "rttp"} "#) .proxy(Proxy::socks5with_authorization("127.0.0.1", 1081, "username", "password")) .emit(); ```
```rust
let response = HttpClient::new().post() .config(Config::builder().autoredirect(true)) .get() .url("http://bing.com") .emit(); assert!(response.isok()); let response = response.unwrap(); assert_ne!("bing.com", response.host()); ```
```rust
let response = HttpClient::new().post() .url("http://httpbin.org/post") .rasync() .await; ```