Skip to content
This repository was archived by the owner on Jun 7, 2024. It is now read-only.

Commit ff42559

Browse files
authored
Merge pull request #3 from wacker-dev/docs
Add more docs
2 parents 88582e4 + 3d0227d commit ff42559

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ jobs:
2020
run: cargo fmt --all -- --check
2121
- name: cargo clippy
2222
run: cargo clippy --all-targets --all-features -- -D warnings
23+
- name: cargo test
24+
run: cargo test

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
11
# wasi-http-client
2-
HTTP client library for WASI.
2+
3+
HTTP client library for [WASI Preview 2](https://github.com/WebAssembly/WASI/tree/main/preview2),
4+
making it easier to send http(s) requests in WASI components.
5+
6+
```rust
7+
let resp = Client::new()
8+
.post("https://httpbin.org/post")
9+
.body("hello".as_bytes())
10+
.connect_timeout(Duration::from_secs(5))
11+
.send()
12+
.unwrap();
13+
14+
println!("status code: {}", resp.status());
15+
```

examples/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Examples
2+
3+
See https://github.com/wacker-dev/wasi-examples/tree/main/http-client for a real-world example.
4+
After compilation, you can use [wasmtime](https://github.com/bytecodealliance/wasmtime) to run it:
5+
6+
```
7+
$ wasmtime -S http target/wasm32-wasi/debug/http_client.wasm
8+
9+
status code: 200
10+
content-type: application/json
11+
content-length: 297
12+
access-control-allow-credentials: true
13+
server: gunicorn/19.9.0
14+
date: Sat, 11 May 2024 09:46:38 GMT
15+
access-control-allow-origin: *
16+
body:
17+
{
18+
"args": {},
19+
"data": "hello",
20+
"files": {},
21+
"form": {},
22+
"headers": {
23+
"Content-Length": "5",
24+
"Host": "httpbin.org",
25+
"X-Amzn-Trace-Id": "Root=1-663f3e7e-6e3f84f87a20aef56c58a344"
26+
},
27+
"json": null,
28+
"origin": "……",
29+
"url": "https://httpbin.org/post"
30+
}
31+
```
32+
33+
There are specific steps for compilation in the [README](https://github.com/wacker-dev/wasi-examples/blob/main/http-client/README.md),
34+
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).

src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
//! # wasi-http-client
2+
//!
3+
//! `wasi_http_client` is an HTTP client library for [WASI Preview 2](https://github.com/WebAssembly/WASI/tree/main/preview2),
4+
//! making it easier to send http(s) requests in WASI components.
5+
//!
6+
//! ```
7+
//! # use std::time::Duration;
8+
//! # use wasi_http_client::Client;
9+
//! # fn run() {
10+
//! let resp = Client::new()
11+
//! .post("https://httpbin.org/post")
12+
//! .body("hello".as_bytes())
13+
//! .connect_timeout(Duration::from_secs(5))
14+
//! .send()
15+
//! .unwrap();
16+
//!
17+
//! println!("status code: {}", resp.status());
18+
//! # }
19+
//! ```
20+
121
mod client;
222
mod request;
323
mod response;

0 commit comments

Comments
 (0)