mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-06 04:38:25 +00:00
Adds a new crate "wasix_http_client", which is a wrapper around the WAI generated sys bindings to the wasix_http_client_v1.wai component. Enables easy http client usage from Rust code.
21 lines
574 B
Rust
21 lines
574 B
Rust
use wasix_http_client::{Body, HttpClient, RequestBuilder};
|
|
|
|
fn main() {
|
|
let c = HttpClient::new().unwrap();
|
|
let r = RequestBuilder::new()
|
|
.uri("http://ferris2.christoph.app.wapm.dev/http-client-test")
|
|
.body(Body::empty())
|
|
.unwrap();
|
|
eprintln!("fetching: {r:?}");
|
|
|
|
let res = c.send(r).unwrap();
|
|
dbg!(&res);
|
|
assert!(res.status().is_success());
|
|
|
|
let body = res.into_body().read_all().unwrap();
|
|
let s = String::from_utf8(body).unwrap();
|
|
eprintln!("Response body: {s}");
|
|
|
|
assert!(s.contains("http-client-test"));
|
|
}
|