Files
wasmer/lib/wasix/wasix-http-client/examples/http_client.rs
Christoph Herzog 7a4358de7a Add wasix_http_client Rust client library
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.
2022-12-11 06:09:31 +01:00

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"));
}