Skip to content

Installation

This guide walks you through setting up your development environment to build WASI HTTP handlers with mik-sdk.

  1. Rust 1.85+ with the wasm32-wasip2 target

    Terminal window
    rustup update
    rustup target add wasm32-wasip2
  2. cargo-component for building WASM components

    Terminal window
    cargo install cargo-component
  3. wac for component composition

    Terminal window
    cargo install wac-cli
  4. wasmtime (optional) for running components locally

    Terminal window
    # Via cargo
    cargo install wasmtime-cli
    # Or via package manager (macOS)
    brew install wasmtime

Create a new handler project:

Terminal window
cargo new --lib my-handler
cd my-handler

Configure 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" }

Your handler needs the mik:core WIT interface. You can get it from the OCI registry or GitHub releases:

Terminal window
# Install oras if you don't have it
cargo install oras
# Download the WIT file
mkdir -p wit/deps/core
oras pull ghcr.io/dufeutech/mik-sdk-wit:latest -o wit/deps/core

Your project structure should look like:

my-handler/
├── Cargo.toml
├── src/
│ └── lib.rs
└── wit/
├── world.wit
└── deps/
└── core/
└── core.wit

Create wit/world.wit:

package my:handler;
world handler {
include mik:core/handler-world;
}

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"] }
FeatureDefaultDescription
sqlYesSQL query builder macros
http-clientYesOutbound HTTP requests

To compose your handler into a runnable service, you need the mik-bridge component:

Terminal window
# Download the bridge component
oras pull ghcr.io/dufeutech/mik-sdk-bridge:latest -o .
# Result: mik_bridge.wasm

Build a minimal handler to verify your setup:

src/lib.rs
#[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:

Terminal window
cargo component build --release

If successful, you’ll find your component at:

target/wasm32-wasip2/release/my_handler.wasm