Skip to content

Commit f223461

Browse files
committed
chore: basic example readme
1 parent c83f6dc commit f223461

13 files changed

Lines changed: 57 additions & 45 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# ic-http-proxy
22

3-
Forum announcement: https://forum.dfinity.org/t/non-replicated-https-outcalls/26627
3+
Forum announcement: https://forum.dfinity.org/t/non-replicated-https-outcalls/26627.
4+
5+
Examples available in the [examples](./examples) folder.
Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/rust/basic/Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[workspace]
2+
members = ["src/basic_backend"]
3+
resolver = "2"

‎examples/rust/basic/README.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Basic example (Rust)
2+
3+
This example contains a [backend canister](./src/basic_backend/) written in Rust that sends HTTP requests via the [Proxy canister](../../../src/proxy_canister/) to external APIs.
4+
5+
## Usage
6+
7+
You can interact with the canister from [its Candid UI interface](https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.icp0.io/?id=ittvb-6qaaa-aaaao-a3agq-cai).
8+
9+
The main method is the [`http_request_via_proxy`](./src/basic_backend/src/lib.rs#L29-L52), which can be invoked to make the HTTP request. The parameters are:
10+
11+
- `req`: the HTTP request parameters (url, method, headers, body).
12+
- `timeout_ms`: the request timeout in milliseconds (optional).
13+
14+
You can try setting this parameter to a value between _5000_ and _60000_ milliseconds and make a GET request to the [httpbin.org](https://httpbin.org/)'s [delay endpoint](https://httpbin.org/#/Dynamic_data/get_delay__delay_) with a bigger delay value to see the request expiring.
15+
16+
- `with_callback`: set it to `true` to receive the response back from the Proxy canister, `false` otherwise.
17+
18+
When set to `true`, the Proxy canister will call the [`http_request_callback`](./src/basic_backend/src/lib.rs#L55-L64) canister method, which will register the response result in the local state.
19+
20+
The `http_request_via_proxy` method will return the response id, which can be used to read the response result from the canister state. In order to read the request result, you can pass the response id as an argument to the [`get_http_result_by_id`](./src/basic_backend/src/lib.rs#L72-L74) method.
21+
22+
Use the [`get_http_results`](./src/basic_backend/src/lib.rs#L67-L69) method to retrieve all the responses' results.
23+
24+
## Deploy the canister on MAINNET
25+
26+
Make sure you have [jq](https://jqlang.github.io/jq) installed.
27+
28+
**Remove** the [canister_ids.json](./canister_ids.json) file from this folder and then run the following command:
29+
30+
```bash
31+
./deploy.sh
32+
```
33+
34+
Note: the script will attempt to get the ID of the HTTP Proxy Canister from the [canister_ids.json](../../../canister_ids.json) file, and pass it as the init argument to the `basic_backend` canister.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"simple_backend": {
2+
"basic_backend": {
33
"ic": "ittvb-6qaaa-aaaao-a3agq-cai"
44
}
55
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ PROXY_CANISTER_ID=$(jq .proxy_canister.ic ../../../canister_ids.json)
66

77
echo "PROXY_CANISTER_ID: $PROXY_CANISTER_ID"
88

9-
dfx deploy --ic simple_backend --argument "(principal $PROXY_CANISTER_ID)"
9+
dfx deploy --ic basic_backend --argument "(principal $PROXY_CANISTER_ID)"
1010

1111
# just to get info about the canister, not needed for deployment
12-
dfx canister --ic status simple_backend
12+
dfx canister --ic status basic_backend
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"canisters": {
3-
"simple_backend": {
4-
"candid": "src/simple_backend/simple_backend.did",
5-
"package": "simple_backend",
3+
"basic_backend": {
4+
"candid": "src/basic_backend/basic_backend.did",
5+
"package": "basic_backend",
66
"type": "rust"
77
}
88
},

examples/rust/simple/src/simple_backend/Cargo.toml renamed to examples/rust/basic/src/basic_backend/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "simple_backend"
2+
name = "basic_backend"
33
version = "0.1.0"
44
edition = "2021"
55

examples/rust/simple/src/simple_backend/simple_backend.did renamed to examples/rust/basic/src/basic_backend/basic_backend.did

File renamed without changes.

0 commit comments

Comments
 (0)