WasmEdge Hyper Demo.

Overview

WasmEdge Hyper Demo

In this project, we demonstrate how to use hyper and tokio to build async http client in WebAssembly and execute it using WasmEdge.

Why tokio in WasmEdge?

There are growing demands to perform network requests in WASM and cloud computing. But it would be inefficient to perform network requests synchronously so we need async in WASM.

As tokio is widely accepted, we can bring many projects that depend on tokio to WASM if we can port tokio into WASM. After that, the developers can have async functions in WASM as well as efficient programs.

With the help of tokio support of WasmEdge, the developers can compile the projects that use tokio into WASM and execute it using WasmEdge.

Prequsites

We need install rust and wasm target first.

# install rust 
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# install wasm target 
rustup target add wasm32-wasi

Then install the WasmEdge. You will need all extensions to run the HTTP server with Tensorflow example.

curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -e all

Add dependencies in Cargo.toml

In this project, we add tokio and reqwest as dependencies.

[dependencies]
hyper = {git = "https://github.com/WasmEdge/hyper.git", branch = "wasmedge", features = ["http1", "server"]}
tokio = { git="https://github.com/WasmEdge/tokio.git", branch = "wasmedge", features=["rt", "macros", "net", "time"]}

Examples

FAQ

use of unstable library feature 'wasi_ext'

If you are using rustc 1.64, you may encounter this error. There are two options:

  1. Update rustc to newer version. Validated versions are 1.65 and 1.59.
  2. Add #![feature(wasi_ext)] to the top of mio/src/lib.rs.
Comments
  • Remove the platforms from the build part

    Remove the platforms from the build part

    These are not needed since there is a platform property on the service level.

    compose has a bug where having both platform and platforms will make docker compose up build for the wrong platform... This can be fixed either by running docker compose build && docker compose up or by removing the platforms from the build property.

    opened by rumpl 0
  • Use wasi/wasm and add the platform to the image properties

    Use wasi/wasm and add the platform to the image properties

    This PR changes the platform name to wasi/wasm, see here for more info, it also adds the platform for the image, it's needed for the next version of docker desktop with the latest updates to the containerd store backed docker daemon.

    opened by rumpl 0
  • Build and run with Docker

    Build and run with Docker

    Prerequisites

    Requires a version of Docker with Wasm support.

    Build

    docker compose build

    Run

    Server: docker compose run --no-TTY server Note: The server process will not stop. You will need to kill the Wasm shim to stop the process.

    Client: docker compose run --no-TTY client

    opened by chris-crone 0
  • Problems running on OSX (12.6)

    Problems running on OSX (12.6)

    Trying to run an example on my machine but I'm running into some weird issues, wondering if there's an easy explanation here

    $ cargo --version                                                                                                                                                                                           
    cargo 1.65.0 (4bc8f24d3 2022-10-20)
    $ cargo build --target wasm32-wasi && wasmedge target/wasm32-wasi/debug/lsat-proxy.wasm                                                                                                                     
        Finished dev [unoptimized + debuginfo] target(s) in 0.07s
    2022-11-22T15:32:18.202591Z  INFO lsat_proxy: Listening on http://0.0.0.0:8080
    // when trying to curl from the second console
    Error: Os { code: 52, kind: Unsupported, message: "Function not implemented" }
    

    Looking at the code it errors exactly here when attempting to accept the incoming connection

     let (stream, _) = listener.accept().await?;
    

    Not sure where to dig from here.

    Edit: side note: running on M1 mac

    opened by bernii 3
  • Build project in OSX

    Build project in OSX

    Hi,

    I am trying to run the example this example: https://github.com/jabrena/101-rust/blob/main/hello_world_wasm_backend/README.md

    But I was not able to compile in OSX, I am receiving the following error:

    docker compose build
    [+] Building 1.3s (14/14) FINISHED                                                                                          
     => [internal] load build definition from Dockerfile                                                                   0.0s
     => => transferring dockerfile: 32B                                                                                    0.0s
     => [internal] load .dockerignore                                                                                      0.0s
     => => transferring context: 2B                                                                                        0.0s
     => [internal] load metadata for docker.io/library/rust:1.64                                                           1.2s
     => [buildbase 1/5] FROM docker.io/library/rust:1.64@sha256:922d814994d77f8e3ab8a7db45a277e9cebe41a557046eeef91a2e34b  0.0s
     => [internal] load build context                                                                                      0.0s
     => => transferring context: 86B                                                                                       0.0s
     => CACHED [buildbase 2/5] RUN rustup target add wasm32-wasi                                                           0.0s
     => CACHED [buildbase 3/5] WORKDIR /src                                                                                0.0s
     => CACHED [buildbase 4/5] COPY src ./src                                                                              0.0s
     => CACHED [buildbase 5/5] COPY Cargo.toml .                                                                           0.0s
     => CACHED [buildserver 1/3] COPY src ./src                                                                            0.0s
     => CACHED [buildserver 2/3] RUN pwd                                                                                   0.0s
     => CACHED [buildserver 3/3] RUN --mount=type=cache,target=/usr/local/cargo/git/db     --mount=type=cache,target=/usr  0.0s
     => CACHED [server 1/1] COPY --from=buildserver /src/target/wasm32-wasi/release/wasmedge_hyper_server.wasm wasmedge_h  0.0s
     => ERROR exporting to image                                                                                           0.0s
     => => exporting layers                                                                                                0.0s
     => => writing image sha256:9811b6619248d3846ca8c70d463c359854511b6539541b40dbfcb799b80e64f2                           0.0s
    ------
     > exporting to image:
    ------
    failed to solve: operating system is not supported
    
    docker compose up          
    [+] Running 0/0
     ⠋ Container hello_world_wasm_backend-server-1  Creating                                                                                                                   0.0s
    Error response from daemon: Unknown runtime specified io.containerd.wasmedge.v1
    

    How to build the example in OSX?

    Many thanks in advance

    Juan Antonio

    opened by jabrena 2
Owner
WasmEdge Runtime
A cloud native WebAssembly runtime. A sandbox project at the CNCF (Cloud Native Computing Foundation) and Linux Foundation.
WasmEdge Runtime
Basic Rust I2C demo on the TI Launchpad

msp430-i2c-oled-example An example project to talk to an SSD1306 OLED (Adafruit PiOLED) with an MSP430G2553 Launchpad via I2C.

Edward Shin 3 Jul 9, 2021
WIP demo project for pure rust playing nicely with MCUBoot/Infinitime OTA

pinetime-rust-mcuboot WIP demo project for pure rust playing nicely with MCUBoot/Infinitime OTA Firmware Behavior This is an example project so I just

David Boles 2 Jan 26, 2022
Demo of tokio running on esp32 using esp-idf

Tokio running on esp32! This repo demonstrates a working hello world utilizing upstreamed tokio support for esp32. The tokio executor and I/O reactor

Josh Guilfoyle 9 Aug 7, 2023
Embedded demo based on esp32-c3

wot-esp-demo Demo Hygro-Thermometer based on the esp-rust-board. http version based on std-training Deploy Rust prerequisites Install espflash, ldprox

null 3 Dec 1, 2023
WasmEdge Reqwest Demo.

WasmEdge Reqwest Demo In this project, we demonstrate how to use reqwest and tokio to build async http client in WebAssembly and execute it using Wasm

WasmEdge Runtime 4 Nov 29, 2022
A high-performance, secure, extensible, and OCI-complaint JavaScript runtime for WasmEdge.

Run JavaScript in WebAssembly Now supporting wasmedge socket for HTTP requests and Tensorflow in JavaScript programs! Prerequisites Install Rust and w

Second State 219 Jan 3, 2023
WasmEdge Host Function Example Interface

A Rust library that provides Rust to WebAssembly developers with syntax for running self-defined host functions when their Wasm is being executed on WasmEdge (formerly SSVM).

Second State 3 Oct 18, 2022
Rust client for the anna-rs KVS that can run in the WasmEdge Runtime

wasmedge-anna-client wasmedge-anna-client is a Rust client for anna-rs based on Tokio for WasmEdge. It communicates with Anna routing nodes and KVS no

WasmEdge Runtime 4 Nov 8, 2022
An experimental Dapr SDK in Rust. It is designed to run in WasmEdge applications.

Dapr SDK for WebAssembly Written in Rust, the dapr_sdk_wasi crate can be compiled into WebAssembly and runs in the WasmEdge Runtime. Introduction | Ho

Second State 18 Jan 3, 2023
A template project for building a database-driven microservice in Rust and run it in the WasmEdge sandbox.

Secure & lightweight microservice with a database backend In this repo, we demonstrate a microservice written in Rust, and connected to a MySQL databa

Second State 222 Feb 19, 2023
A lightweight web framework built on hyper, implemented in Rust language.

Sapper Sapper, a lightweight web framework, written in Rust. Sapper focuses on ergonomic usage and rapid development. It can work with stable Rust. Sa

Daogang Tang 622 Oct 27, 2022
Sincere is a micro web framework for Rust(stable) based on hyper and multithreading

The project is no longer maintained! Sincere Sincere is a micro web framework for Rust(stable) based on hyper and multithreading. Style like koa. The

null 94 Oct 26, 2022
Node.js http server framework powered by Hyper native binding.

hnsjs POC project. Install this test package yarn add @hnsjs/core Support matrix node10 node12 node14 node15 Windows x64 ✓ ✓ ✓ ✓ Windows x32 ✓ ✓ ✓ ✓

LongYinan 18 Nov 23, 2022
axum-server is a hyper server implementation designed to be used with axum framework.

axum-server axum-server is a hyper server implementation designed to be used with axum framework. Features Conveniently bind to any number of addresse

null 79 Jan 4, 2023
Ergonomic and modular web framework built with Tokio, Tower, and Hyper

axum axum is a web application framework that focuses on ergonomics and modularity. More information about this crate can be found in the crate docume

Tokio 7.9k Dec 31, 2022
A synchronous HTTP server built on hyper.

Astra Astra is a synchronous HTTP server built on top of hyper. use astra::{Body, Response, Server}; fn main() { Server::bind("localhost:3000")

Ibraheem Ahmed 23 Nov 27, 2022
Rate Limiting middleware for Tower/Axum/Tonic/Hyper utilizing the governor crate

A Tower service and layer that provides a rate-limiting backend by governor. Based heavily on the work done for actix-governor. Works with Axum, Hyper

Ben Wishovich 31 Feb 15, 2023
A simple API gateway written in Rust, using the Hyper and Reqwest libraries.

API Gateway A simple API gateway written in Rust, using the Hyper and Reqwest libraries. This gateway can be used to forward requests to different bac

Adão Raul 3 Apr 24, 2023
hyper.rs with boringssl configured to impersonate chrome

hyper.rs with boringssl configured to impersonate chrome. Just lemme do HTTPS request from rust to web server behind cloudflare or akamai. is it so scary? i dont think so.

makin 4 Apr 23, 2023
Natural language detection library for Rust. Try demo online: https://www.greyblake.com/whatlang/

Whatlang Natural language detection for Rust with focus on simplicity and performance. Content Features Get started Documentation Supported languages

Sergey Potapov 805 Dec 28, 2022