This project template is a WebAssembly component built with Rust that demonstrates an HTTP handler with routing, query parameters, and JSON request and response bodies.
The component uses axum for routing, wired to wasi:http/incoming-handler via wstd-axum. Standard axum runs on tokio plus hyper. Inside a Wasm component, HTTP arrives through the host-imported wasi:http interface, so neither tokio's networking stack nor hyper's socket layer applies. wstd-axum adapts an axum::Router onto the wasi:http/incoming-handler export. The Cargo.toml opts out of axum's default features and only enables those that do not require tokio or hyper.
- Wasm Shell (
wash) - Rust toolchain
- The
wasm32-wasip2Rust target:rustup target add wasm32-wasip2
Use wash new to scaffold a new wasmCloud component project:
wash new https://github.com/wasmCloud/wasmCloud.git --name http-handler --subfolder templates/http-handlercd http-handlerTo build this project and run in a hot-reloading development loop, run wash dev from this directory:
wash dev| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Returns a hello message |
/api/greet |
GET | Returns Hello, <name>! (uses the name query parameter, defaults to world) |
/api/echo |
POST | Echoes the JSON request body |
curl http://localhost:8000/
curl 'http://localhost:8000/api/greet?name=Eric'
curl -X POST http://localhost:8000/api/echo \
-H 'Content-Type: application/json' \
-d '{"message":"hello"}'wash buildThis component exports the following WIT interfaces:
world http-handler {
export wasi:http/incoming-handler@0.2.2;
}