#http-client #wasm-edge #http #https #client #wasm #http-request

http_req_wasi

WasmEdge网络套接字API的HTTP客户端。由http_req库派生。

5个版本

0.11.1 2023年5月23日
0.11.0 2023年5月19日
0.10.2 2023年1月14日
0.10.1 2022年10月1日
0.10.0 2022年9月29日

1390网络编程

Download history 278/week @ 2024-05-02 611/week @ 2024-05-09 304/week @ 2024-05-16 252/week @ 2024-05-23 252/week @ 2024-05-30 160/week @ 2024-06-06 221/week @ 2024-06-13 238/week @ 2024-06-20 169/week @ 2024-06-27 66/week @ 2024-07-04 387/week @ 2024-07-11 322/week @ 2024-07-18 258/week @ 2024-07-25 270/week @ 2024-08-01 264/week @ 2024-08-08 249/week @ 2024-08-15

1,065 每月下载量
22 个Crate中使用了(21个直接使用)

MIT 许可证

115KB
2.5K SLoC

http_req_wasi

简单轻量级的HTTP客户端,用于底层wasmedge_wasi_socket库。它将被编译成WebAssembly字节码目标,并在WasmEdge运行时中以轻量级和安全的替代品运行Linux容器中本机编译的应用程序。

该项目是从http_req项目派生的,该项目由jayjamesjay创建。

示例

HTTPS中的基本GET请求

use http_req::request;

fn main() {
    let mut writer = Vec::new(); //container for body of a response
    let res = request::get("https://httpbin.org/get?msg=WasmEdge", &mut writer).unwrap();

    println!("Status: {} {}", res.status_code(), res.reason());
    println!("Headers {}", res.headers());
    println!("{}", String::from_utf8_lossy(&writer));
}

如何使用

[dependencies]
http_req_wasi  = "0.10"

构建和运行

首先安装WasmEdge,然后按照以下步骤安装HTTPS插件。

# Download and extract the plugin
wget https://github.com/WasmEdge/WasmEdge/releases/download/0.11.1/WasmEdge-plugin-wasmedge_httpsreq-0.11.1-manylinux2014_x86_64.tar.gz
tar -xzf WasmEdge-plugin-wasmedge_httpsreq-0.11.1-manylinux2014_x86_64.tar.gz

# Install the plugin if your wasmedge is installed in ~/.wasmedge
cp libwasmedgePluginHttpsReq.so ~/.wasmedge/plugin/

# Install the plugin if your wasmedge is installed in /usr/local
cp libwasmedgePluginHttpsReq.so /usr/local/lib/wasmedge/

构建GET HTTPS示例。

cargo wasi build --release --example get_https

运行示例。

wasmedge target/wasm32-wasi/release/examples/get_https.wasm

Status: 200 OK
Headers {
  Content-Length: 292
  Date: Tue, 04 Oct 2022 20:07:47 GMT
  Access-Control-Allow-Origin: *
  Access-Control-Allow-Credentials: true
  Server: gunicorn/19.9.0
  Content-Type: application/json
  Connection: close
}
{
  "args": {
    "msg": "WasmEdge"
  }, 
  "headers": {
    "Host": "httpbin.org", 
    "Referer": "https://httpbin.org/get?msg=WasmEdge", 
    "X-Amzn-Trace-Id": "Root=1-633c9293-390dc4cc46f268412e39a208"
  }, 
  "origin": "13.84.49.116", 
  "url": "https://httpbin.org/get?msg=WasmEdge"
}

依赖项

~1MB
~19K SLoC