This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from wacker-dev/docs
Add more docs
- Loading branch information
Showing
4 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
# wasi-http-client | ||
HTTP client library for WASI. | ||
|
||
HTTP client library for [WASI Preview 2](https://github.com/WebAssembly/WASI/tree/main/preview2), | ||
making it easier to send http(s) requests in WASI components. | ||
|
||
```rust | ||
let resp = Client::new() | ||
.post("https://httpbin.org/post") | ||
.body("hello".as_bytes()) | ||
.connect_timeout(Duration::from_secs(5)) | ||
.send() | ||
.unwrap(); | ||
|
||
println!("status code: {}", resp.status()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Examples | ||
|
||
See https://github.com/wacker-dev/wasi-examples/tree/main/http-client for a real-world example. | ||
After compilation, you can use [wasmtime](https://github.com/bytecodealliance/wasmtime) to run it: | ||
|
||
``` | ||
$ wasmtime -S http target/wasm32-wasi/debug/http_client.wasm | ||
status code: 200 | ||
content-type: application/json | ||
content-length: 297 | ||
access-control-allow-credentials: true | ||
server: gunicorn/19.9.0 | ||
date: Sat, 11 May 2024 09:46:38 GMT | ||
access-control-allow-origin: * | ||
body: | ||
{ | ||
"args": {}, | ||
"data": "hello", | ||
"files": {}, | ||
"form": {}, | ||
"headers": { | ||
"Content-Length": "5", | ||
"Host": "httpbin.org", | ||
"X-Amzn-Trace-Id": "Root=1-663f3e7e-6e3f84f87a20aef56c58a344" | ||
}, | ||
"json": null, | ||
"origin": "……", | ||
"url": "https://httpbin.org/post" | ||
} | ||
``` | ||
|
||
There are specific steps for compilation in the [README](https://github.com/wacker-dev/wasi-examples/blob/main/http-client/README.md), | ||
and the main logic of the sample program is located at [lib.rs](https://github.com/wacker-dev/wasi-examples/blob/main/http-client/src/lib.rs#L14-L19). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters