Code Monkey home page Code Monkey logo

http_req's Introduction

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

http_req's People

Contributors

2019zhou avatar breard-r avatar cedriccouton avatar colelawrence avatar devashishdxt avatar fauxfaux avatar fxcojrqd avatar hydai avatar jaycefayne avatar jayjamesjay avatar jetjinser avatar juntao avatar l-jasmine avatar piotr-roslaniec avatar tsurai avatar voidumbrella avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.