An experimental Dapr SDK in Rust. It is designed to run in WasmEdge applications.

Overview

Dapr SDK for WebAssembly

Written in Rust, the dapr_sdk_wasi crate can be compiled into WebAssembly and runs in the WasmEdge Runtime.

Introduction | How it works | Contribution

Introduction

This software is still under development, we welcome new contributors!

WebAssembly provides a secure, fast, and lightweight runtime sandbox for cloud-native applications, especially for microservices, as an alternative to Linux containers and VMs. The dapr_sdk_wasi crate is a Rust SDK for the Dapr framework. It provides an easy way for Rust-based microservices in WasmEdge to interact with Dapr APIs and sidecar services. The figure below shows a Dapr-enabled microservice running inside the WasmEdge sandbox.

Currently, the dapr-sdk-wasi supports Dapr's service invocation, state management, secrets, and health APIs.

Dapr API Status
Service invocation API
State management API
Pub/sub API To be done
Bindings API To be done
Actors API To be done
Secrets API
Configuration API To be done
Distributed Lock API To be done
Health API
Metadata API To be done

How it works

This repo contains the SDK, a Dapr service example, and an example client to access the Dapr service using the SDK.

  • The root project is the SDK, which is provides a Rust API to call Dapr API services.
  • examples/echo is a microservice demo that runs with a Dapr sidecar.
  • examples/tests is a SDK client that accesses Dapr APIs on the sidecar.

If you want to run the echo example and SDK tests, follow the following instructions.

Install Rust and add Wasi target for the Rust compiler

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32-wasi

Install WasmEdge

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

Install and init Dapr

wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash
dapr init

Run the echo example

cd examples/echo

// compile the rust code to wasm 
cargo build --target wasm32-wasi --release
wasmedgec target/wasm32-wasi/release/dapr_echo.wasm dapr_echo.wasm

// Use Dapr to start the echo microservice application
dapr run --app-id echo-service --app-protocol http --app-port 9004 --dapr-http-port 3502 --components-path ../config --log-level debug wasmedge dapr_echo.wasm

// Shows the server log
ℹ️  Starting Dapr with id echo-service. HTTP Port: 3502. gRPC Port: 44517
time="2022-10-07T22:00:17.732779744Z" level=info msg="starting Dapr Runtime -- version 1.8.4 -- commit 18575823c74318c811d6cd6f57ffac76d5debe93" app_id=echo-service instance=fv-az186-200 scope=dapr.runtime type=log ver=1.8.4
time="2022-10-07T22:00:17.732813444Z" level=info msg="log level set to: debug" app_id=echo-service instance=fv-az186-200 scope=dapr.runtime type=log ver=1.8.4
···

Run the SDK tests

Do the following from another terminal window from the echo service.

cd examples/tests

// compile the SDK testing code to wasm
cargo build --target wasm32-wasi --release
wasmedgec target/wasm32-wasi/release/dapr_examples.wasm dapr_examples.wasm

// Run the tests to interact with the `echo` service's Dapr sidecar from WasmEdge
wasmedge dapr_examples.wasm

// Results from the tests on the console
URL is http://localhost:3502/v1.0/healthz/
Status code is 204
Dapr echo is healthy!
URL is http://localhost:3502/v1.0/invoke/echo-service/method/echo
Echo: {"message":"WasmEdge"}
URL is http://localhost:3502/v1.0/state/starwars
Saved!
URL is http://localhost:3502/v1.0/state/starwars/weapon
State for weapon: "DeathStar"
URL is http://localhost:3502/v1.0/state/starwars/bulk
State for weapon and planet: [{"data":"DeathStar","etag":"1","key":"weapon"},{"data":{"name":"Tatooine"},"etag":"1","key":"planet"}]
URL is http://localhost:3502/v1.0/state/starwars/weapon
Deleted!
URL is http://localhost:3502/v1.0/state/starwars/bulk
State for weapon and planet: [{"key":"weapon"},{"data":{"name":"Tatooine"},"etag":"1","key":"planet"}]
URL is http://localhost:3502/v1.0/state/starwars/transaction
Transacted!
URL is http://localhost:3502/v1.0/state/starwars/bulk
State for weapon, planet, key1 and key2: [{"key":"weapon"},{"data":{"name":"Tatooine"},"etag":"1","key":"planet"},{"data":"myData","etag":"1","key":"key1"},{"key":"key2"}]
URL is http://localhost:3502/v1.0/secrets/local-store/DB_URL:MYSQL
Secret for DB_URL:MYSQL {"DB_URL:MYSQL":"***127.0.0.1:3306/mysql"}

Contribution

Any feedback is appreciated. If you have any questions or suggestions, please raise an issue or create a PR and let us know.

If you prefer chatting in real-time, join our Discord server.

Tech stacks used in this project

  • Tokio
  • hyper
  • reqwest
  • Dapr
  • WasmEdge
You might also like...
A console and web-based Gomoku written in Rust and WebAssembly
A console and web-based Gomoku written in Rust and WebAssembly

👋 rust-gomoku A console and web-based Gomoku written in Rust and WebAssembly Getting started with cargo & npm Install required program, run # install

darkforest is a console and web-based Roguelike written in Rust and WebAssembly.
darkforest is a console and web-based Roguelike written in Rust and WebAssembly.

darkforest darkforest is a console and web-based Roguelike written in Rust and WebAssembly. Key Features TBA Quick Start TBA How To Contribute Contrib

MORUS cipher for Rust.

MORUS for Rust This is a Rust implementation of MORUS (MORUS-1280-128), ported from the Zig implementation. MORUS is a fast authenticated cipher for p

A Rust ESP stack trace decoder that can also runs in your browser thanks to WebAssembly
A Rust ESP stack trace decoder that can also runs in your browser thanks to WebAssembly

ESP Stack Trace Decoder A Rust ESP stack trace decoder that can also runs in your browser thanks to WebAssembly. It is composed of a ⌨️ Rust library,

Simple file sharing with client-side encryption, powered by Rust and WebAssembly
Simple file sharing with client-side encryption, powered by Rust and WebAssembly

Hako Simple file sharing with client-side encryption, powered by Rust and WebAssembly Not feature-packed, but basic functionalities are just working.

Wasm runtime written in Rust

Wasm runtime written in Rust

bn.js bindings for Rust & WebAssembly with primitive-types support

bn.rs bn.js bindings for Rust & WebAssembly with primitive-types support Write Rust code that uses BN use std::str::FromStr; use primitive_types::{H1

A handy calculator, based on Rust and WebAssembly.
A handy calculator, based on Rust and WebAssembly.

qubit 💥 Visit Website To Use Calculator Example 💥 Visit Website To Use Calculator 2 + 2

A simple compile-to-WebAssembly language rewritten in Rust

chasm A very simple compile-to-WebAssembly language You can play with chasm online. This is a rewrite in Rust of the compiler for the language chasm.

Owner
Second State
Fast, safe, portable & serverless. Deploy Rust functions in edge computing, Jamstack, SaaS and service mesh applications.
Second State
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
A (very experimental) WebAssembly backend for Cranelift.

cranelift_codegen_wasm Experimental code generation for WebAssembly from Cranelift IR. note: not ready for usage yet Setup Contains an item called Was

Teymour Aldridge 8 Dec 5, 2022
⚙️ Experimental JVM bytecode to WebAssembly compiler

⚙️ montera Final year university project: a highly experimental JVM bytecode to WebAssembly compiler ⚠️ Do NOT use this for serious projects yet! It's

MrBBot 7 Oct 24, 2022
🚀Wasmer is a fast and secure WebAssembly runtime that enables super lightweight containers to run anywhere

Wasmer is a fast and secure WebAssembly runtime that enables super lightweight containers to run anywhere: from Desktop to the Cloud, Edge and IoT devices.

Wasmer 14.1k Jan 8, 2023
Stylist is a CSS-in-Rust styling solution for WebAssembly Applications.

Stylist Stylist is a CSS-in-Rust styling solution for WebAssembly Applications. This is a fork of css-in-rust. Install Add the following to your Cargo

Kaede Hoshikawa 190 Dec 30, 2022
Zaplib is an open-source library for speeding up web applications using Rust and WebAssembly.

⚡ Zaplib Zaplib is an open-source library for speeding up web applications using Rust and WebAssembly. It lets you write high-performance code in Rust

Zaplib 1.2k Jan 5, 2023
Sealed boxes implementation for Rust/WebAssembly.

Sealed boxes for Rust/WebAssembly This Rust crate provides libsodium sealed boxes for WebAssembly. Usage: // Recipient: create a new key pair let reci

Frank Denis 16 Aug 28, 2022
WebAssembly on Rust is a bright future in making application runs at the Edge or on the Serverless technologies.

WebAssembly Tour WebAssembly on Rust is a bright future in making application runs at the Edge or on the Serverless technologies. We spend a lot of ti

Thang Chung 129 Dec 28, 2022
Autogenerated async RPC bindings that instantly connect a JS frontend to a Rust backend service via WebSockets and WASM.

Turbocharger Autogenerated async RPC bindings that instantly connect a JS frontend to a Rust backend service via WebSockets and WASM. See https://gith

null 28 Jan 2, 2023