Skip to content

Library to make HTTPs outcalls from a canister on the Internet Computer, leveraging the modularity of the tower framework.

License

Notifications You must be signed in to change notification settings

dfinity/canhttp

Repository files navigation

Internet Computer portal DFinity Forum GitHub license

canhttp

Library to make HTTPs outcalls from a canister on the Internet Computer, leveraging the modularity of the tower framework.

Usage

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.

Cargo Features

Feature http

Offers middleware that transforms a low-level service that uses Candid types into one that uses types from the http crate.

Feature json

Offers middleware that transforms a low-level service that transmits bytes into one that transmits JSON payloads.

Feature multi

Make multiple calls in parallel and handle their multiple results.

License

This project is licensed under the Apache License 2.0.

About

Library to make HTTPs outcalls from a canister on the Internet Computer, leveraging the modularity of the tower framework.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages