| Crates.io | ic-pocket-canister-runtime |
| lib.rs | ic-pocket-canister-runtime |
| version | 0.2.0 |
| created_at | 2025-11-24 09:18:34.33395+00 |
| updated_at | 2025-12-09 12:24:29.16944+00 |
| description | Canisters runtime on the Internet Computer using Pocket IC |
| homepage | https://github.com/dfinity/canhttp |
| repository | https://github.com/dfinity/canhttp |
| max_upload_size | |
| id | 1947564 |
| size | 116,920 |
ic-pocket-canister-runtimeImplementation of the ic_canister_runtime crate's Runtime trait for PocketIC allowing to mock
HTTPs outcalls.
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.
This project is licensed under the Apache License 2.0.