GithubHelp home page GithubHelp logo

wasmedge_hyper_demo's Introduction

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.

Quickstart with Docker

The easiest way to get started is to use a version of Docker Desktop or Docker CLI with Wasm support.

Then, you just need to type one command.

docker compose up

It runs both the client and server examples in this repo. See the Dockerfile and docker-compose.yml files. The client example will run and quit upon completion. The server example starts a server that listens for incoming HTTP requests, and you can interact with it through curl.

However, if you want to build and run the examples step by step on your own system. Follow the detailed instructions below.

Prerequisites

We need install rust and wasm target first.

# install rust 
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env

# 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
source $HOME/.wasmedge/env

Add dependencies in Cargo.toml

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

[dependencies]
hyper_wasi = { version = "0.15", features = ["full"]}
tokio_wasi = { version = "1.21", features = ["rt", "macros", "net", "time", "io-util"]}

Examples

Details about the example apps are as below.

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.

wasmedge_hyper_demo's People

Contributors

captainvincent avatar chris-crone avatar hydai avatar juntao avatar mediosz 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.