WasmEdge Reqwest Demo.

Overview

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 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.

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

Add dependencies in Cargo.toml

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

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

Write the code

We need to add some code into src/main.rs.

Build and run it

First we need to compile the code.

cargo build --target wasm32-wasi

Then we can run it using WasmEdge.

wasmedge target/wasm32-wasi/debug/wasmedge_reqwest_demo.wasm

For simpilicity, we can add the following configs to .cargo/config.toml.

[build]
target="wasm32-wasi"

[target.wasm32-wasi]
runner = "wasmedge"

And then we can use cargo run to execute it directly.

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.
You might also like...
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

💫 This program allows you to do requests in Rust without reqwest !

Zapros 💫 This program allows you to do requests in Rust without reqwest ! Usage : Get use crate::http_client::HttpClient; use crate::http_client::Htt

Natural language detection library for Rust. Try demo online: https://www.greyblake.com/whatlang/
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

A working demo of RustDesk server implementation

A working demo of RustDesk server implementation This is a super simple working demo implementation with only one relay connection allowed, without NA

Demo for the swash font library

Demo for the swash crate See the swash repo or crate for the actual project. This is a chunk of very rough code.

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.

Source code from Atlas, our 64k demo presented at Revision 2019 with Macau Exports

Atlas source code dump This is a dump of the source code for the engine, graphics tool and player for Atlas, our 64k demo released with Macau Exports

Demo Terraform Provider in Rust

terraform-provider-helloworld Welcome to a large pile of hacks masquerading as a PoC. This repository proves that it's possible to write a Terraform P

Demo for Arduboy written in rust
Demo for Arduboy written in rust

arduboy-hello-rs Install Install Rust with rustup https://www.rust-lang.org/en-US/install.html Install Arduino IDE https://www.arduino.cc/en/Main/Soft

A demo blog post engine in Rust, using Rocket and MongoDB
A demo blog post engine in Rust, using Rocket and MongoDB

A demo blog post engine written in Rust, using Rocket and MongoDB Quick Start Setup a new MongoDB cluster https://cloud.mongodb.com/ create a new data

A mini-game demo of BonsaiDb + Gooey

"Minority Game" Demo Why build this? This repository originally was created for a presentation at the December Rust Gamedev Meetup. @ecton recorded th

A Demo server serving Bert through ONNX with GPU written in Rust with 3

Demo BERT ONNX server written in rust This demo showcase the use of onnxruntime-rs on BERT with a GPU on CUDA 11 served by actix-web and tokenized wit

This is a small demo to accompany the Tauri + Yew tutorial

Tauri + Yew Demo This is a small demo to accompany the Tauri + Yew tutorial

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

Quick demo of a REST frontend with a Redis session store.

axum-rest-starter-example Important Tasks Ensure session UUID is unique Protect /api/ with JWT Add CSRF CORS? Dev Setup (1) Run docker compose up to f

Small ray tracer demo of the F# to Rust language transpiler in Fable 4.x

Small ray tracer demo of the F# to Rust language transpiler in Fable 4.x

Rust libp2p and tokio demo

Rust libp2p and tokio demo This repository contains code to show basic usage of the async programming using tokio and p2p - libp2p library in Rust. Th

Demo of Rust and axum web framework

Demo of Rust and axum web framework Demonstration of: Rust: programming language that focuses on reliability and stability. axum: web framework that f

A very bare-bone Block Chain demo that purely implemented by Rust and yew
A very bare-bone Block Chain demo that purely implemented by Rust and yew

Intro bloc is one of bare-bone blockchain demo written by Rust, Yew during my learning BlockChain, about years ago. see demo here It just demonstrate

Comments
  • [Bug] Bad link in readme

    [Bug] Bad link in readme

    Currently this link in the readme https://github.com/WasmEdge/wasmedge_reqwest_demo/blob/02f1b29ff3c61a615d309030e0a41684df8a4d23/README.md?plain=1#L3

    Resolves to: https://github.com/WasmEdge/wasmedge_reqwest_demo/blob/main

    opened by willemneal 0
Owner
WasmEdge Runtime
A cloud native WebAssembly runtime. A sandbox project at the CNCF (Cloud Native Computing Foundation) and Linux Foundation.
WasmEdge Runtime
WasmEdge Hyper Demo.

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

WasmEdge Runtime 23 Dec 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
Wrapper around reqwest to allow for client middleware chains.

reqwest-middleware A crate implementing a wrapper around reqwest to allow for client middleware chains. Overview The reqwest-middleware client exposes

TrueLayer 113 Dec 7, 2022
Small crate to extend `reqwest` to be able to send with digest auth flow.

diqwest This crate extends reqwest to be able to send requests with digest auth flow. It is currently implemented for async usage only. When you send

Mathias Oertel 14 Aug 29, 2022
An API for getting questions from http://either.io implemented fully in Rust, using reqwest and some regex magic. Provides asynchronous and blocking clients respectively.

eithers_rust An API for getting questions from http://either.io implemented fully in Rust, using reqwest and some regex magic. Provides asynchronous a

null 2 Oct 24, 2021
HTTP microservice using Axum and Reqwest to request the Google Translate TTS endpoint without rate limits

HTTP microservice using Axum and Reqwest to request the Google Translate TTS endpoint without rate limits

Gnome! 5 Oct 5, 2022