Crates.io | reqwest_wasi |
lib.rs | reqwest_wasi |
version | 0.11.16 |
source | src |
created_at | 2022-10-02 00:39:11.715584 |
updated_at | 2023-11-15 02:30:26.64233 |
description | higher level HTTP client library |
homepage | |
repository | https://github.com/wasmedge/reqwest |
max_upload_size | |
id | 678090 |
size | 705,992 |
An ergonomic, batteries-included HTTP Client for Rust. This is a fork from the original reqwest with support for WebAssembly compilation target. That allows reqwest apps to run inside the WasmEdge Runtime as a lightweight and secure alternative to natively compiled apps in Linux container.
For more details and usage examples, please see the upstream reqwest source and these examples.
Note: We do not yet support SSL / TLS connections in reqwest_wasi yet.
This asynchronous example uses Tokio and enables some
optional features, so your Cargo.toml
could look like this:
[dependencies]
reqwest_wasi = { version = "0.11", features = ["json"] }
tokio_wasi = { version = "1.21", features = ["full"] }
And then the code:
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let resp = reqwest::get("http://eu.httpbin.org/ip")
.await?
.json::<HashMap<String, String>>()
.await?;
println!("{:#?}", resp);
Ok(())
}
There is an optional "blocking" client API that can be enabled:
[dependencies]
reqwest_wasi = { version = "0.11", features = ["blocking", "json"] }
use std::collections::HashMap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let resp = reqwest::blocking::get("http://eu.httpbin.org/ip")?
.json::<HashMap<String, String>>()?;
println!("{:#?}", resp);
Ok(())
}
Licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.