Module hyper::client [] [src]

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();
});

Reexports

pub use self::pool::Pool;
pub use self::request::Request;
pub use self::response::Response;

Modules

pool

Client Connection Pooling

request

Client Requests

response

Client Responses

Structs

Client

A Client to use additional features with Requests.

RequestBuilder

Options for an individual Request.

Enums

Body

An enum of possible body types for a Request.

RedirectPolicy

Behavior regarding how to handle redirects within a Client.

Traits

IntoUrl

A helper trait to convert common objects into a Url.