ic-pocket-canister-runtime

Crates.ioic-pocket-canister-runtime
lib.rsic-pocket-canister-runtime
version0.2.0
created_at2025-11-24 09:18:34.33395+00
updated_at2025-12-09 12:24:29.16944+00
descriptionCanisters runtime on the Internet Computer using Pocket IC
homepagehttps://github.com/dfinity/canhttp
repositoryhttps://github.com/dfinity/canhttp
max_upload_size
id1947564
size116,920
(dfinity-publish)

documentation

https://docs.rs/ic-pocket-canister-runtime

README

Internet Computer portal DFinity Forum GitHub license

ic-pocket-canister-runtime

Implementation of the ic_canister_runtime crate's Runtime trait for PocketIC allowing to mock HTTPs outcalls.

Usage

Add this to your Cargo.toml (see crates.io for the latest version):

ic-canister-runtime = "0.1.0"
ic-pocket-canister-runtime = "0.1.0"

Then, use the library to mock HTTP outcalls for canister deployed with PocketIC, as follows:

use ic_canister_runtime::Runtime;
use ic_pocket_canister_runtime::{
    AnyCanisterHttpRequestMatcher, CanisterHttpReply, MockHttpOutcallsBuilder,
    MockHttpRuntime
};
use pocket_ic::nonblocking::PocketIc;

let mocks = MockHttpOutcallsBuilder::new()
    .given(AnyCanisterHttpRequestMatcher)
    .respond_with(
        CanisterHttpReply::with_status(200)
            .with_body(r#"{"data": "Hello, World!", "headers": {"X-Id": "42"}}"#)
    );

let pocket_ic = PocketIc::new().await;
let runtime = MockHttpRuntime::new(&pocket_ic, Principal::anonymous())
    .with_http_mocks(mocks.build());

let http_request_result: String = runtime
    .update_call(canister_id, "make_http_post_request", (), 0)
    .await
    .expect("Call to `http_canister` failed");

assert!(http_request_result.contains("Hello, World!"));
assert!(http_request_result.contains("\"X-Id\": \"42\""));

See the Rust documentation for more details.

License

This project is licensed under the Apache License 2.0.

Commit count: 0

cargo fmt