mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 13:18:20 +00:00
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.
This commit is contained in:
20
lib/wasix/wasix-http-client/examples/http_client.rs
Normal file
20
lib/wasix/wasix-http-client/examples/http_client.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
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"));
|
||||
}
|
||||
Reference in New Issue
Block a user