Module sp_runtime::offchain::http[][src]

A high-level helpers for making HTTP requests from Offchain Workers.

sp-io crate exposes a low level methods to make and control HTTP requests available only for Offchain Workers. Those might be hard to use and usually that level of control is not really necessary. This module aims to provide high-level wrappers for those APIs to simplify making HTTP requests.

Example:

use sp_runtime::offchain::http::Request;

// initiate a GET request to localhost:1234
let request: Request = Request::get("http://localhost:1234");
let pending = request
	.add_header("X-Auth", "hunter2")
	.send()
	.unwrap();

// wait for the response indefinitely
let mut response = pending.wait().unwrap();

// then check the headers
let mut headers = response.headers().into_iter();
assert_eq!(headers.current(), None);

// and collect the body
let body = response.body();
assert_eq!(body.clone().collect::<Vec<_>>(), b"1234".to_vec());
assert_eq!(body.error(), &None);

Structs

Headers

A collection of Headers in the response.

HeadersIterator

A custom iterator traversing all the headers.

PendingRequest

A struct representing an uncompleted http request.

Request

An HTTP request builder.

Response

A HTTP response.

ResponseBody

A buffered byte iterator over response body.

Enums

Error

A request error

Method

Request method (HTTP verb)

Type Definitions

HttpResult

A result of waiting for a pending request.