Installation
This guide walks you through setting up your development environment to build WASI HTTP handlers with mik-sdk.
Prerequisites
Section titled “Prerequisites”-
Rust 1.85+ with the
wasm32-wasip2targetTerminal window rustup updaterustup target add wasm32-wasip2 -
cargo-component for building WASM components
Terminal window cargo install cargo-component -
wac for component composition
Terminal window cargo install wac-cli -
wasmtime (optional) for running components locally
Terminal window # Via cargocargo install wasmtime-cli# Or via package manager (macOS)brew install wasmtime
Project Setup
Section titled “Project Setup”Create a new handler project:
cargo new --lib my-handlercd my-handlerConfigure Cargo.toml:
[package]name = "my-handler"version = "0.1.0"edition = "2024"
[lib]crate-type = ["cdylib"]
[dependencies]mik-sdk = "0.1"
[package.metadata.component]package = "my:handler"
[package.metadata.component.target.dependencies]"mik:core" = { path = "wit/deps/core" }WIT Dependencies
Section titled “WIT Dependencies”Your handler needs the mik:core WIT interface. You can get it from the OCI registry or GitHub releases:
# Install oras if you don't have itcargo install oras
# Download the WIT filemkdir -p wit/deps/coreoras pull ghcr.io/dufeutech/mik-sdk-wit:latest -o wit/deps/core# Download from the latest releasemkdir -p wit/deps/corecurl -L https://github.com/dufeutech/mik-sdk/releases/latest/download/core.wit \ -o wit/deps/core/core.witCopy the wit/ directory from examples/hello-world/ in the mik-sdk repository.
Your project structure should look like:
my-handler/├── Cargo.toml├── src/│ └── lib.rs└── wit/ ├── world.wit └── deps/ └── core/ └── core.witCreate wit/world.wit:
package my:handler;
world handler { include mik:core/handler-world;}Feature Flags
Section titled “Feature Flags”mik-sdk provides optional features:
[dependencies]# Default (includes SQL macros + HTTP client)mik-sdk = "0.1"
# Minimal (no SQL, no HTTP client)mik-sdk = { version = "0.1", default-features = false }
# Only SQL (no HTTP client)mik-sdk = { version = "0.1", default-features = false, features = ["sql"] }| Feature | Default | Description |
|---|---|---|
sql | Yes | SQL query builder macros |
http-client | Yes | Outbound HTTP requests |
Bridge Component
Section titled “Bridge Component”To compose your handler into a runnable service, you need the mik-bridge component:
# Download the bridge componentoras pull ghcr.io/dufeutech/mik-sdk-bridge:latest -o .# Result: mik_bridge.wasm# Download from the latest releasecurl -LO https://github.com/dufeutech/mik-sdk/releases/latest/download/mik-bridge.wasmVerify Installation
Section titled “Verify Installation”Build a minimal handler to verify your setup:
#[allow(warnings)]mod bindings;
use bindings::exports::mik::core::handler::{self, Guest, Response};use mik_sdk::prelude::*;
routes! { GET "/" => home,}
fn home(_req: &Request) -> Response { ok!({ "message": "Hello from mik-sdk!" })}Build the component:
cargo component build --releaseIf successful, you’ll find your component at:
target/wasm32-wasip2/release/my_handler.wasmNext Steps
Section titled “Next Steps”- Quick Start - Build a complete handler
- Routing - Learn the routing system
- Architecture - Understand the component model