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

http_req_wasi

HTTP client for the WasmEdge network socket API. Derived from the http_req library.

5 releases

0.11.1 May 23, 2023
0.11.0 May 19, 2023
0.10.2 Jan 14, 2023
0.10.1 Oct 1, 2022
0.10.0 Sep 29, 2022

#124 in HTTP client

Download history 236/week @ 2024-07-22 299/week @ 2024-07-29 219/week @ 2024-08-05 324/week @ 2024-08-12 185/week @ 2024-08-19 210/week @ 2024-08-26 216/week @ 2024-09-02 287/week @ 2024-09-09 240/week @ 2024-09-16 253/week @ 2024-09-23 257/week @ 2024-09-30 40/week @ 2024-10-07 172/week @ 2024-10-14 185/week @ 2024-10-21 201/week @ 2024-10-28 218/week @ 2024-11-04

776 downloads per month
Used in 22 crates (21 directly)

MIT license

115KB
2.5K SLoC

http_req_wasi

Simple and lightweight HTTP client for the low level wasmedge_wasi_socket library. It is to be compiled into WebAssembly bytecode targets and runs in the WasmEdge Runtime as a lightweight and secure alternative to natively compiled apps in Linux container.

This project is forked and derived from the http_req project created by jayjamesjay.

Example

Basic GET request in HTTPS

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

How to use:

[dependencies]
http_req_wasi  = "0.10"

Build and run

Install WasmEdge and then install the HTTPS plugin as follows.

# 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/

Build the GET HTTPS example.

cargo wasi build --release --example get_https

Run the example.

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

Dependencies

~1MB
~19K SLoC