This repository was archived by the owner on Jun 7, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +70
-1
lines changed Expand file tree Collapse file tree 4 files changed +70
-1
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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+ ```
Original file line number Diff line number Diff line change 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 ) .
Original file line number Diff line number Diff line change 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+
121mod client;
222mod request;
323mod response;
You can’t perform that action at this time.
0 commit comments