{"id":21659639,"url":"https://github.com/second-state/dapr-wasm","last_synced_at":"2025-10-10T02:42:00.721Z","repository":{"id":37424016,"uuid":"394897735","full_name":"second-state/dapr-wasm","owner":"second-state","description":"A template project to demonstrate how to run WebAssembly functions as sidecar microservices in dapr","archived":false,"fork":false,"pushed_at":"2023-12-03T06:42:51.000Z","size":32545,"stargazers_count":283,"open_issues_count":5,"forks_count":24,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-07-18T00:36:25.068Z","etag":null,"topics":["dapr","golang","microservice","rust","rust-lang","sidecar","wasmedge","webassembly"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/second-state.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-08-11T07:15:13.000Z","updated_at":"2025-06-30T00:52:36.000Z","dependencies_parsed_at":"2024-11-25T09:43:21.433Z","dependency_job_id":null,"html_url":"https://github.com/second-state/dapr-wasm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/second-state/dapr-wasm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/second-state%2Fdapr-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/second-state%2Fdapr-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/second-state%2Fdapr-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/second-state%2Fdapr-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/second-state","download_url":"https://codeload.github.com/second-state/dapr-wasm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/second-state%2Fdapr-wasm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002541,"owners_count":26083403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dapr","golang","microservice","rust","rust-lang","sidecar","wasmedge","webassembly"],"created_at":"2024-11-25T09:31:20.079Z","updated_at":"2025-10-10T02:42:00.671Z","avatar_url":"https://github.com/second-state.png","language":"Rust","readme":"# Dapr and WasmEdge\n\n[Tutorial video](https://www.youtube.com/watch?v=3v37pAT9iK8)\n\n## Introduction\n\nThis is a template application to showcase how [Dapr](https://dapr.io/) and [WasmEdge](https://github.com/WasmEdge/) work together to support [lightweight WebAssembly-based microservices](https://github.com/second-state/microservice-rust-mysql) in a cloud-native environment. The microservices are all written in Rust and compiled into WebAssembly. They run inside the WasmEdge Runtime [as opposed to Linux containers](https://wasmedge.org/wasm_linux_container/) or VMs for these reasons.\n\n\u003e While this demo is done in Rust, WasmEdge can also run [Node.js compatible JavaScript](https://wasmedge.org/book/en/write_wasm/js.html) applications. \n \nThis application consists of 3 microservices and a [standalone web page](docs) that enables users to interact with the microservices using a HTML+JavaScript UI. It is a very typical JAMstack setup. Each microservice is attached to a Dapr sidecar, which provides a suite of useful services commonly required by cloud-native microservices. The overall architecture is as follows.\n\n\u003cimg src=\"docs/dapr-wasmedge.png\" alt=\"Microservices architecture\" width=\"480\" style=\"text-align: center; margin: 0 auto;\"/\u003e\n\nThe Rust version of [Dapr SDK for WasmEdge](https://github.com/second-state/dapr-sdk-wasi) is used to access Dapr sidecars from the microservice apps. Specifically, the [grayscale](https://github.com/second-state/dapr-wasm/tree/main/image-api-grayscale) microservice takes an image from an HTTP POST, turns it into grayscale, and returns the result image data in the HTTP response. \n\n* It uses Dapr to discover and invoke the [events](https://github.com/second-state/dapr-wasm/tree/main/events-service) microservice to record every successful user request. \n* It also stores each user’s IP address and last timestamp data in its Dapr sidecar’s state database. That allows the service to rate limit users if needed. \n\nThe [classify](https://github.com/second-state/dapr-wasm/tree/main/image-api-classify) microservices takes an image from an HTTP POST, runs a Tensorflow model against it to classify the object on the image, and returns the result as a text label in the HTTP response. You can learn more about AI inference in Rust and WasmEdge [here](https://wasmedge.org/book/en/write_wasm/rust/wasinn.html). It uses its own Dapr sidecar the same way as the [grayscale](https://github.com/second-state/dapr-wasm/tree/main/image-api-grayscale) microservice. \n\nThe [events](https://github.com/second-state/dapr-wasm/tree/main/events-service) microservice takes JSON data from a HTTP POST and saves it to an external MySQL database for later analysis. \n\n* It uses Dapr to make itself discoverable by name by other microservices that need to record events. \n* It also uses its Dapr sidecar to store secrets such as the MySQL database credentials.\n\nNow, go ahead and fork this repo. Create and deploy your own lightweight microservices for better security, faster performance, and smaller footprints. \n\n## Build and deploy these microservices in Dapr\n\nYou will need install the following software toolchain to run these examples. The detailed steps are shown in the [GitHub Actions script](.github/workflows/main.yml).\n\n* [Install the Dapr CLI](https://docs.dapr.io/getting-started/install-dapr-cli/)\n* [Install the WasmEdge Runtime](https://wasmedge.org/docs/develop/build-and-run/install)\n* [Install Rust](https://www.rust-lang.org/tools/install)\n* Install the [MySQL](https://dev.mysql.com/doc/mysql-installation-excerpt/5.7/en/) or [MariaDB](https://mariadb.com/kb/en/getting-installing-and-upgrading-mariadb/) or [TiDB](https://docs.pingcap.com/tidb/dev/quick-start-with-tidb) databases\n\nStart the database and place the connection string in the [config/secrets.json](config/secrets.json) file under `DB_URL:MYSQL`. Next, start Dapr with the following commands.\n\n```bash\ndapr init\n```\n\n### The image grayscale microservice\n\nBuild.\n\n```bash\ncd image-api-grayscale\ncargo build --target wasm32-wasi --release\nwasmedge compile ./target/wasm32-wasi/release/image-api-grayscale.wasm image-api-grayscale.wasm\n```\n\nDeploy.\n\n```bash\ndapr run --app-id image-api-grayscale \\\n        --app-protocol http \\\n        --app-port 9005 \\\n        --dapr-http-port 3503 \\\n        --components-path ../config \\\n        --log-level debug \\\n\twasmedge image-api-grayscale.wasm\n```\n\n### The image classification microservice\n\nBuild.\n\n```bash\ncd image-api-classify\ncargo build --target wasm32-wasi --release\nwasmedge compile target/wasm32-wasi/release/wasmedge_hyper_server_tflite.wasm wasmedge_hyper_server_tflite.wasm\n```\n\nDeploy.\n\n```bash\ndapr run --app-id image-api-classify \\\n        --app-protocol http \\\n        --app-port 9006 \\\n        --dapr-http-port 3504 \\\n        --log-level debug \\\n        --components-path ../config \\\n        wasmedge wasmedge_hyper_server_tflite.wasm\n```\n\n### The events recorder microservice\n\nBuild.\n\n```bash\ncd events-service\ncargo build --target wasm32-wasi --release\nwasmedge compile target/wasm32-wasi/release/events_service.wasm events_service.wasm\n```\n\nDeploy.\n\n```bash\ndapr run --app-id events-service \\\n        --app-protocol http \\\n        --app-port 9007 \\\n        --dapr-http-port 3505 \\\n        --log-level debug \\\n        --components-path ../config \\\n        wasmedge events_service.wasm\n```\n\n### Test\n\nYou can use the [static web page UI](http://dapr-demo.secondstate.co/) or `curl` to test the services.\n\nInitialize the events database table.\n\n```bash\n$ curl http://localhost:9007/init\n{\"status\":true}\n\n$ curl http://localhost:9007/events\n[]\n```\n\nUse the grayscale microservice. The return data is base64 encoded grayscale image.\n\n```bash\n$ cd docs\n$ curl http://localhost:9005/grayscale -X POST --data-binary '@food.jpg'\nABCDEFG ...\n```\n\nUse the image classification microservice.\n\n```bash\n$ cd docs\n$ curl http://localhost:9006/classify -X POST --data-binary '@food.jpg'\nhotdog is detected with 255/255 confidence\n```\n\nQuery the events database again.\n\n```bash\n$ curl http://localhost:9007/events\n[{\"id\":1,\"event_ts\":1665358852918,\"op_type\":\"grayscale\",\"input_size\":68016},{\"id\":2,\"event_ts\":1665358853114,\"op_type\":\"classify\",\"input_size\":68016}]\n```\n\n## Learn more\n\n* Why WebAssembly as a cloud native runtime: https://wasmedge.org/wasm_linux_container/\n* Create a high-performance HTTP server in WasmEdge: https://github.com/WasmEdge/wasmedge_hyper_demo/tree/main/server\n* Create a web service client in WasmEdge: https://github.com/WasmEdge/wasmedge_reqwest_demo\n* Create a database client in WasmEdge: https://github.com/WasmEdge/wasmedge-db-examples\n* Dapr SDK for WasmEdge and examples: https://github.com/second-state/dapr-sdk-wasi\n* Using container tools (Kubernetes, Docker, Podman etc) to manage WadmEdge apps: https://wasmedge.org/book/en/use_cases/kubernetes.html\n* Run JavaScript and Node.js apps in WasmEdge: https://wasmedge.org/book/en/write_wasm/js.html\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecond-state%2Fdapr-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsecond-state%2Fdapr-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecond-state%2Fdapr-wasm/lists"}