Module hyper::client [−][src]
Expand description
HTTP Client
Usage
The Client
API is designed for most people to make HTTP requests.
It utilizes the lower level Request
API.
GET
let client = Client::new();
let res = client.get("http://example.domain").send().unwrap();
assert_eq!(res.status, hyper::Ok);
The returned value is a Response
, which provides easy access to
the status
, the headers
, and the response body via the Read
trait.
POST
let client = Client::new();
let res = client.post("http://example.domain")
.body("foo=bar")
.send()
.unwrap();
assert_eq!(res.status, hyper::Ok);
Sync
The Client
implements Sync
, so you can share it among multiple threads
and make multiple requests simultaneously.
use std::sync::Arc;
use std::thread;
// Note: an Arc is used here because `thread::spawn` creates threads that
// can outlive the main thread, so we must use reference counting to keep
// the Client alive long enough. Scoped threads could skip the Arc.
let client = Arc::new(Client::new());
let clone1 = client.clone();
let clone2 = client.clone();
thread::spawn(move || {
clone1.get("http://example.domain").send().unwrap();
});
thread::spawn(move || {
clone2.post("http://example.domain/post").body("foo=bar").send().unwrap();
});
Re-exports
Modules
Structs
A Client to use additional features with Requests.
Proxy server configuration with a custom connector and TLS wrapper.
Options for an individual Request.
Enums
An enum of possible body types for a Request.
Behavior regarding how to handle redirects within a Client.
Traits
A helper trait to convert common objects into a Url.