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

Commit

Permalink
Add more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
iawia002 committed May 13, 2024
1 parent 88582e4 commit 3d0227d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ jobs:
run: cargo fmt --all -- --check
- name: cargo clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: cargo test
run: cargo test
15 changes: 14 additions & 1 deletion README.md
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());
```
34 changes: 34 additions & 0 deletions examples/README.md
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).
20 changes: 20 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
//! # wasi-http-client
//!
//! `wasi_http_client` is an 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.
//!
//! ```
//! # use std::time::Duration;
//! # use wasi_http_client::Client;
//! # fn run() {
//! 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());
//! # }
//! ```

mod client;
mod request;
mod response;
Expand Down

0 comments on commit 3d0227d

Please sign in to comment.