[][src]Module reqwest::blocking

A blocking Client API.

The blocking Client will block the current thread to execute, instead of returning futures that need to be executed on a runtime.

Optional

This requires the optional blocking feature to be enabled.

Making a GET request

For a single request, you can use the get shortcut method.


let body = reqwest::blocking::get("https://www.rust-lang.org")?
    .text()?;

println!("body = {:?}", body);

Additionally, the blocking Response struct implements Rust's Read trait, so many useful standard library and third party crates will have convenience methods that take a Response anywhere T: Read is acceptable.

NOTE: If you plan to perform multiple requests, it is best to create a Client and reuse it, taking advantage of keep-alive connection pooling.

Making POST requests (or setting request bodies)

There are several ways you can set the body of a request. The basic one is by using the body() method of a RequestBuilder. This lets you set the exact raw bytes of what the body should be. It accepts various types, including String, Vec<u8>, and File. If you wish to pass a custom Reader, you can use the reqwest::blocking::Body::new() constructor.

let client = reqwest::blocking::Client::new();
let res = client.post("http://httpbin.org/post")
    .body("the exact body that is sent")
    .send()?;

And More

Most features available to the asynchronous Client are also available, on the blocking Client, see those docs for more.

Modules

multipart

multipart/form-data

Structs

Body

The body of a Request.

Client

A Client to make Requests with.

ClientBuilder

A ClientBuilder can be used to create a Client with custom configuration.

Request

A request which can be executed with Client::execute().

RequestBuilder

A builder to construct the properties of a Request.

Response

A Response to a submitted Request.

Functions

get

Shortcut method to quickly make a blocking GET request.