HTTP client
HTTP client example
This WASI P2 component makes outgoing HTTP requests using wasi:http/outgoing-handler. It demonstrates GET, POST, and header inspection against the companion http-server example as well as an external endpoint httpbin.org.
Source Code
The source code is available in the examples/addition directory.
Loading...
Create Task
To create a task for this example, we need to build the example to wasm and then create a task with the wasm file.
cd propeller
make http-clientNow we can create a task with the wasm file:
curl -X POST "http://localhost:7070/tasks" \
-H "Content-Type: application/json" \
-d '{"name": "_start"}'Your output should look like this:
{
"id": "71509cb7-fadd-4a28-9f63-0487edbf983f",
"name": "_start",
"kind": "standard",
"state": 0,
"cli_args": null,
"daemon": false,
"encrypted": false,
"start_time": "0001-01-01T00:00:00Z",
"finish_time": "0001-01-01T00:00:00Z",
"created_at": "2026-02-13T14:41:34.403038919Z",
"updated_at": "0001-01-01T00:00:00Z",
"next_run": "0001-01-01T00:00:00Z",
"priority": 50
}Upload Wasm
Now we need to upload the wasm file:
curl -X PUT "http://localhost:7070/tasks/71509cb7-fadd-4a28-9f63-0487edbf983f/upload" \
-F "file=@$(pwd)/build/http-client.wasm"Your output should look like this:
{
"id": "71509cb7-fadd-4a28-9f63-0487edbf983f",
"name": "_start",
"kind": "standard",
"state": 0,
"file": "...<redacted>...",
"cli_args": null,
"daemon": false,
"encrypted": false,
"start_time": "0001-01-01T00:00:00Z",
"finish_time": "0001-01-01T00:00:00Z",
"created_at": "2026-02-13T14:41:34.403038919Z",
"updated_at": "2026-02-13T14:42:09.983681995Z",
"next_run": "0001-01-01T00:00:00Z",
"priority": 50
}Start Task
Now we can start the task:
curl -X POST "http://localhost:7070/tasks/71509cb7-fadd-4a28-9f63-0487edbf983f/start"Your output should look like this:
{ "started": true }The results of the task will be something like this.
curl -X GET "http://localhost:7070/tasks/71509cb7-fadd-4a28-9f63-0487edbf983f"Your output should look like this:
{
"id": "71509cb7-fadd-4a28-9f63-0487edbf983f",
"name": "_start",
"kind": "standard",
"state": 3,
"file": "...<redacted>...",
"cli_args": null,
"daemon": false,
"encrypted": false,
"proplet_id": "a95517f9-5655-4cf5-a7c8-aa00290b3895",
"results": "",
"start_time": "2026-02-13T14:42:50.765861837Z",
"finish_time": "2026-02-13T14:42:53.006292588Z",
"created_at": "2026-02-13T14:41:34.403038919Z",
"updated_at": "2026-02-13T14:42:53.006292537Z",
"next_run": "0001-01-01T00:00:00Z",
"priority": 50
}Invoking Using WasmTime
wasmtime -Shttp ./build/http-client.wasmThe results of the task will be something like this.
=== GET https://httpbin.org/get ===
Status: 200 OK
{
"args": {},
"headers": {
"Host": "httpbin.org",
"X-Amzn-Trace-Id": "Root=1-698f3800-1fd69a163ed11ee75fdffa79"
},
"origin": "105.163.156.155",
"url": "https://httpbin.org/get"
}
=== POST https://httpbin.org/post ===
Status: 200 OK
{
"args": {},
"data": "hello from proplet wasm client",
"files": {},
"form": {},
"headers": {
"Content-Length": "30",
"Content-Type": "text/plain",
"Host": "httpbin.org",
"X-Amzn-Trace-Id": "Root=1-698f3801-72d0b73d324a815a0ad26790"
},
"json": null,
"origin": "105.163.156.155",
"url": "https://httpbin.org/post"
}