Library to make HTTPs outcalls from a canister on the Internet Computer, leveraging the modularity of the tower framework.
Add this to your Cargo.toml (see crates.io for the latest version):
canhttp = "0.2.1"Then, use the library to create an HTTP POST request, as follows:
let request = http::Request::post("https://httpbin.org/anything")
.max_response_bytes(1_000)
.header("X-Id", "42")
.body("Hello, World!".as_bytes().to_vec())
.unwrap();
let response = http_client()
.ready()
.await
.expect("Client should be ready")
.call(request)
.await
.expect("Request should succeed");Complete examples are available here and see also the Rust documentation for more details.
Offers middleware that transforms a low-level service that uses Candid types into one that uses types from the http crate.
Offers middleware that transforms a low-level service that transmits bytes into one that transmits JSON payloads.
Make multiple calls in parallel and handle their multiple results.
This project is licensed under the Apache License 2.0.