Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/send_http_get.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: send_http_get

on:
push:
branches: [master]
pull_request:
paths:
- motoko/send_http_get/**
- .github/workflows/send_http_get.yml

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
motoko-send_http_get:
runs-on: ubuntu-24.04
container: ghcr.io/dfinity/icp-dev-env-motoko:0.3.2
env:
ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Deploy and test
working-directory: motoko/send_http_get
run: |
icp network start -d
icp deploy
make test
20 changes: 0 additions & 20 deletions motoko/send_http_get/.devcontainer/devcontainer.json

This file was deleted.

3 changes: 3 additions & 0 deletions motoko/send_http_get/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# dfx temporary files
.dfx/

# icp-cli cache
.icp/

# generated files
src/declarations/

Expand Down
113 changes: 0 additions & 113 deletions motoko/send_http_get/BUILD.md

This file was deleted.

22 changes: 6 additions & 16 deletions motoko/send_http_get/Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
.PHONY: all
all: build

.PHONY: build
.SILENT: build
build:
dfx deploy send_http_get_backend

.PHONY: test
.SILENT: test
test: build
dfx canister call send_http_get_backend send_http_get_request \
| grep 'hello-from-icp' && echo 'PASS'

.PHONY: clean
.SILENT: clean
clean:
rm -fr .dfx
test:
@echo "=== Test 1/1: send_http_get_request returns JSON with greeting field ==="
@result=$$(icp canister call backend send_http_get_request '()') && \
echo "$$result" && \
echo "$$result" | grep -q 'hello-from-icp' && \
echo "PASS" || (echo "FAIL" && exit 1)
32 changes: 17 additions & 15 deletions motoko/send_http_get/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
# HTTP: GET

The purpose of this dapp is to give developers a minimal dapp that uses the IC's HTTPS outcalls feature to make a `GET` request.
This example demonstrates how to use the Internet Computer's HTTPS outcalls feature to make a `GET` request from a Motoko canister. It sends a request to `postman-echo.com` and returns the echoed JSON response, showing how to pass query parameters and headers through HTTP outcalls.

This demo goes in hand with the [developer documentation on HTTPS outcalls](https://internetcomputer.org/docs/building-apps/network-features/using-http/https-outcalls/get).
## Build and deploy from the command line

## Deploying from ICP Ninja
### Prerequisites
- Node.js
- icp-cli: `npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm`

[![](https://icp.ninja/assets/open.svg)](https://icp.ninja/editor?g=https://github.com/dfinity/examples/tree/master/motoko/send_http_get)
### Install

## Build and deploy from the command-line

### 1. [Download and install the IC SDK.](https://internetcomputer.org/docs/building-apps/getting-started/install)

### 2. Download your project from ICP Ninja using the 'Download files' button on the upper left corner, or [clone the GitHub examples repository.](https://github.com/dfinity/examples/)

### 3. Navigate into the project's directory.
```bash
git clone https://github.com/dfinity/examples
cd examples/motoko/send_http_get
```

### 4. Deploy the project to your local environment:
### Deploy and test

```
dfx start --background --clean && dfx deploy
```bash
icp network start -d
icp deploy
make test
icp network stop
```

## Security considerations and best practices

If you base your application on this example, it is recommended that you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/building-apps/security/overview) for developing on ICP. This example may not implement all the best practices.
Refer to the [security best practices](https://docs.internetcomputer.org/guides/security/overview) for information on security and best practices for your ICP app.
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import Blob "mo:core/Blob";
import Text "mo:core/Text";
import IC "ic:aaaaa-aa";
import { ic } "mo:ic";
import IC "mo:ic/Types";

persistent actor {
persistent actor SendHttpGet {

// #region transform
// Strip HTTP response headers (date, cookies, tracking IDs) that vary across replicas.
// In replicated mode, all replicas must see an identical response for consensus to
// succeed — the transform ensures this by discarding non-deterministic fields.
public query func transform({
context : Blob;
response : IC.http_request_result;
}) : async IC.http_request_result {
response : IC.HttpRequestResult;
}) : async IC.HttpRequestResult {
{ response with headers = [] };
};
// #endregion transform

// #region get_request
public func send_http_get_request() : async Text {
let request : IC.http_request_args = {
let request : IC.HttpRequestArgs = {
url = "https://postman-echo.com/get?greeting=hello-from-icp";
// Always set max_response_bytes to a tight bound. The cycle cost scales
// with this value, not the actual response size. If omitted, the system
Expand All @@ -36,11 +37,11 @@ persistent actor {

// Cycles must be explicitly attached to management canister calls.
// The amount is based on request size and max_response_bytes.
let response = await (with cycles = 230_949_972_000) IC.http_request(request);
let response = await (with cycles = 230_949_972_000) ic.http_request(request);

// postman-echo.com echoes back the request metadata as JSON, letting you
// verify the query params and headers were sent correctly.
switch (Text.decodeUtf8(response.body)) {
switch (response.body.decodeUtf8()) {
case (?text) text;
case null "Response is not valid UTF-8";
};
Expand Down
15 changes: 0 additions & 15 deletions motoko/send_http_get/dfx.json

This file was deleted.

4 changes: 4 additions & 0 deletions motoko/send_http_get/icp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
canisters:
- name: backend
recipe:
type: "@dfinity/motoko@v5.0.0"
18 changes: 10 additions & 8 deletions motoko/send_http_get/mops.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Motoko dependencies (https://mops.one/)

[toolchain]
moc = "1.5.1"
moc = "1.9.0"

[dependencies]
core = "2.4.0"
core = "2.5.0"
ic = "4.0.0"

[moc]
# M0236: use context dot notation (e.g. map.get(k) instead of Map.get(map, compare, k))
# M0237: redundant explicit implicit arguments (e.g. Nat.compare is inferred automatically)
# M0223: redundant type instantiation (e.g. Array.tabulate instead of Array.tabulate<T>)
args = ["-W=M0236,M0237,M0223"]
# M0236: use context dot notation
# M0237: redundant explicit implicit arguments
# M0223: redundant type instantiation
args = ["--default-persistent-actors", "-W=M0236,M0237,M0223"]

[canisters.backend]
main = "backend/app.mo"
Loading