Learn Wasmcloud - 10 Code Examples & CST Typing Practice Test
WasmCloud is a distributed, actor-based framework for building cloud-native applications using WebAssembly (Wasm), enabling secure, portable, and scalable microservices across heterogeneous environments.
View all 10 Wasmcloud code examples →
Learn WASMCLOUD with Real Code Examples
Updated Nov 25, 2025
Code Sample Descriptions
Simple wasmCloud Actor (Rust)
# wasmcloud/demo/src/lib.rs
use wasmcloud_actor_core::prelude::*;
use wasmcloud_actor_http_server::prelude::*;
#[actor::init]
pub fn init() {}
#[actor::handler]
pub fn handle(req: Request) -> HandlerResult<Response> {
Ok(Response::ok().body("Hello, wasmCloud!"))
}
A basic wasmCloud actor written in Rust that responds with 'Hello, wasmCloud!' when invoked.
wasmCloud Actor Returning JSON
# wasmcloud/demo/json.rs
use wasmcloud_actor_core::prelude::*;
use wasmcloud_actor_http_server::prelude::*;
use serde_json::json;
#[actor::init]
pub fn init() {}
#[actor::handler]
pub fn handle(_req: Request) -> HandlerResult<Response> {
let body = json!({"message": "Hello JSON!"}).to_string();
Ok(Response::ok().body(&body).with_header("Content-Type", "application/json"))
}
Responds with JSON data from a wasmCloud actor.
wasmCloud Actor Reading Query Params
# wasmcloud/demo/query.rs
use wasmcloud_actor_core::prelude::*;
use wasmcloud_actor_http_server::prelude::*;
#[actor::init]
pub fn init() {}
#[actor::handler]
pub fn handle(req: Request) -> HandlerResult<Response> {
let query = req.query_params.get("name").unwrap_or(&"Guest".to_string());
Ok(Response::ok().body(format!("Hello, {}!", query)))
}
Reads query parameters from the request.
wasmCloud Actor Handling POST
# wasmcloud/demo/post.rs
use wasmcloud_actor_core::prelude::*;
use wasmcloud_actor_http_server::prelude::*;
#[actor::init]
pub fn init() {}
#[actor::handler]
pub fn handle(req: Request) -> HandlerResult<Response> {
if req.method == "POST" {
Ok(Response::ok().body(req.body))
} else {
Ok(Response::ok().status(405).body("Method Not Allowed"))
}
}
Handles POST requests and echoes JSON body.
wasmCloud Actor with Custom Header
# wasmcloud/demo/header.rs
use wasmcloud_actor_core::prelude::*;
use wasmcloud_actor_http_server::prelude::*;
#[actor::init]
pub fn init() {}
#[actor::handler]
pub fn handle(_req: Request) -> HandlerResult<Response> {
Ok(Response::ok().body("Custom Header Added").with_header("X-Custom", "wasmCloud"))
}
Adds a custom header to the response.
wasmCloud Actor Redirect
# wasmcloud/demo/redirect.rs
use wasmcloud_actor_core::prelude::*;
use wasmcloud_actor_http_server::prelude::*;
#[actor::init]
pub fn init() {}
#[actor::handler]
pub fn handle(_req: Request) -> HandlerResult<Response> {
Ok(Response::ok().status(302).with_header("Location", "https://example.com"))
}
Redirects request to another URL.
wasmCloud Actor Calling External API
# wasmcloud/demo/fetch.rs
use wasmcloud_actor_core::prelude::*;
use wasmcloud_actor_http_server::prelude::*;
use reqwest;
#[actor::init]
pub fn init() {}
#[actor::handler]
pub fn handle(_req: Request) -> HandlerResult<Response> {
let res = reqwest::blocking::get("https://api.github.com")?.text()?;
Ok(Response::ok().body(res))
}
Fetches data from an external API and returns it.
wasmCloud Actor Conditional Response
# wasmcloud/demo/conditional.rs
use wasmcloud_actor_core::prelude::*;
use wasmcloud_actor_http_server::prelude::*;
#[actor::init]
pub fn init() {}
#[actor::handler]
pub fn handle(req: Request) -> HandlerResult<Response> {
if req.query_params.get("action") == Some(&"ping".to_string()) {
Ok(Response::ok().body("pong"))
} else {
Ok(Response::ok().body("unknown action"))
}
}
Responds differently based on query parameter.
wasmCloud Actor Using Environment Variable
# wasmcloud/demo/env.rs
use wasmcloud_actor_core::prelude::*;
use wasmcloud_actor_http_server::prelude::*;
#[actor::init]
pub fn init() {}
#[actor::handler]
pub fn handle(_req: Request) -> HandlerResult<Response> {
let key = std::env::var("MY_API_KEY").unwrap_or("NotSet".to_string());
Ok(Response::ok().body(format!("API Key length: {}", key.len())))
}
Uses an environment variable to customize response.
wasmCloud Actor Returning HTML
# wasmcloud/demo/html.rs
use wasmcloud_actor_core::prelude::*;
use wasmcloud_actor_http_server::prelude::*;
#[actor::init]
pub fn init() {}
#[actor::handler]
pub fn handle(_req: Request) -> HandlerResult<Response> {
let html = "<!DOCTYPE html><html><body><h1>Hello, wasmCloud!</h1></body></html>";
Ok(Response::ok().body(html).with_header("Content-Type", "text/html"))
}
Returns a simple HTML page from an actor.
Frequently Asked Questions about Wasmcloud
What is Wasmcloud?
WasmCloud is a distributed, actor-based framework for building cloud-native applications using WebAssembly (Wasm), enabling secure, portable, and scalable microservices across heterogeneous environments.
What are the primary use cases for Wasmcloud?
Cloud-native microservices with language portability. Edge computing and IoT applications. Secure serverless functions. Multi-cloud or hybrid-cloud deployments. Composable backend services with minimal runtime overhead
What are the strengths of Wasmcloud?
Language-agnostic: write actors in any Wasm-supported language. Strong isolation for secure microservices. Portable across clouds and operating systems. Scales horizontally without complex infrastructure. Lightweight runtime reduces resource overhead
What are the limitations of Wasmcloud?
Smaller ecosystem compared to traditional cloud frameworks. Requires understanding of actor model and capabilities. Debugging WebAssembly actors can be challenging. Limited UI-focused support (primarily backend/edge services). Complexity in orchestrating large-scale actor lattices
How can I practice Wasmcloud typing speed?
CodeSpeedTest offers 10+ real Wasmcloud code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.