Skip to content

CLI Reference

The mik CLI provides commands for creating, building, and running WASI HTTP projects. It includes an embedded runtime, so you only need one binary.

Terminal window
cargo install mik

Create a new mik project with all required files.

Terminal window
mik new <NAME> [OPTIONS]

Options:

FlagDescription
--libInitialize as a library (default: handler)

Example:

Terminal window
mik new my-api
cd my-api
mik build -rc
mik run

Generated structure:

my-api/
├── Cargo.toml # Component package
├── mik.toml # Project config
├── wit/
│ ├── world.wit # WIT world definition
│ └── deps/core/ # Core handler interface
├── src/
│ └── lib.rs # Handler implementation
├── modules/ # Dependencies directory
└── .gitignore

Build the WASM handler and optionally compose with bridge.

Terminal window
mik build [OPTIONS]

Options:

FlagDescription
-r, --releaseBuild with optimizations
-c, --composeCompose with HTTP bridge

Examples:

Terminal window
# Debug build
mik build
# Release build
mik build -r
# Release build + compose with bridge
mik build -rc

Output:

  • target/wasm32-wasip2/release/<name>.wasm - Compiled handler
  • dist/<name>-composed.wasm - Composed component (with -c)

Start development server with watch mode and embedded services.

Terminal window
mik dev [OPTIONS]

Options:

FlagDescription
--port <PORT>Server port (default: 3000)
--no-servicesSkip starting embedded services

Features:

  • Auto-rebuilds on source changes (watch mode)
  • Auto-starts daemon for embedded services (KV, SQL, Storage, Cron)
  • Runs in foreground with nice output
  • Graceful shutdown on Ctrl+C

Example:

Terminal window
mik dev # Watch mode on port 3000
mik dev --port 8080 # Custom port
mik dev --no-services # Skip embedded services

Output:

Starting development server...
Services available at http://127.0.0.1:9919
KV: /kv/:key
SQL: /sql/query, /sql/execute
Storage: /storage/*path
Cron: /cron
Watching for changes...
Server: http://127.0.0.1:3000
Press Ctrl+C to stop

Start the HTTP server with the embedded runtime.

Terminal window
mik run [COMPONENT] [OPTIONS]

Arguments:

ArgumentDescription
COMPONENTOptional path to a .wasm file

Options:

FlagDescription
--port <PORT>Server port (default: 3000)
--workers <N>Number of worker processes (0 = auto)
--lbEnable integrated L7 load balancer
--localBind to localhost only
--detachRun as background instance with services
--name <NAME>Instance name when detached (default: “default”)

Modes:

All modes use consistent /run/<module>/* routing.

Foreground mode (default):

Terminal window
mik run # Multi-module from mik.toml
mik run dist/api.wasm # Single component

Detached mode (background with services):

Terminal window
mik run --detach # Background instance
mik run --detach --name prod --port 8080

Auto-starts daemon if not running. Use mik ps to list instances.

Multi-worker mode (for performance):

Terminal window
mik run --workers 4 --lb # LB on 3000, workers on 3001-3004
mik run --workers 0 --lb # Auto-detect workers

Example output:

Starting server on http://127.0.0.1:3000
Routes: /run/my-api/* -> component
Health: /health
Metrics: /metrics

Built-in endpoints:

EndpointDescription
/healthHealth check
/metricsPrometheus metrics
/static/*Static files (if configured)

Add a dependency to the project.

Terminal window
mik add <PACKAGE> [OPTIONS]

Package formats:

user/repo # OCI: ghcr.io/user/repo:latest
user/repo:tag # OCI: ghcr.io/user/repo:tag

Options:

FlagDescription
--git <URL>Git repository URL
--path <PATH>Local path
--tag <TAG>OCI/Git tag
--branch <BRANCH>Git branch

Examples:

Terminal window
# Add from OCI registry
mik add dufeutech/router
# Add with specific version
mik add dufeutech/router:v1.0.0
# Add from git
mik add my-component --git "https://github.com/user/repo.git"
# Add local dependency
mik add my-handler --path "../my-handler"

Remove a dependency from the project.

Terminal window
mik remove <PACKAGE>

Synchronize dependencies from registries.

Terminal window
mik sync

Downloads missing dependencies and removes stale modules from modules/.

When to use:

  • After git clone to download all dependencies
  • After switching branches
  • To clean up unused modules

Manage the AOT compilation cache.

Terminal window
mik cache <SUBCOMMAND>

Subcommands:

CommandDescription
infoShow cache statistics
cleanRemove stale entries
clearClear all cached data

Generate shell completion scripts for tab completion support.

Terminal window
mik completions <SHELL>

Supported shells: bash, zsh, fish, powershell, elvish

Installation:

Terminal window
# Bash
mik completions bash > ~/.local/share/bash-completion/completions/mik
# Zsh (add fpath+=~/.zfunc to .zshrc first)
mik completions zsh > ~/.zfunc/_mik
# Fish
mik completions fish > ~/.config/fish/completions/mik.fish
# PowerShell
mik completions powershell >> $PROFILE

Commands for managing background WASM instances. The daemon is auto-managed - it starts automatically when needed and stops when the last instance is stopped.

Stop a running instance.

Terminal window
mik stop [NAME]

Arguments:

ArgumentDescription
NAMEInstance name (default: “default”)

Example:

Terminal window
mik stop # Stop "default" instance
mik stop prod # Stop named instance

When the last instance is stopped, the daemon automatically exits.


List all instances.

Terminal window
mik ps

Example output:

NAME PORT PID STATUS UPTIME
────────────────────────────────────────────────────────
default 3000 12345 running 2h 15m
dev 3001 12346 running 45m

View instance logs.

Terminal window
mik logs [NAME] [OPTIONS]

Options:

FlagDescription
-f, --followFollow log output
-n, --lines <N>Number of lines (default: 50)

VariableDescription
PORTOverride server port
HOSTBind address (default: 127.0.0.1)
RUST_LOGLog level (error, warn, info, debug, trace)
MIK_HOT_RELOADEnable hot reload mode
MIK_API_KEYAPI key for daemon authentication (optional)

Terminal window
# 1. Create project
mik new my-api
cd my-api
# 2. Build with composition
mik build -rc
# 3. Start development server (watch mode + services)
mik dev
# 4. Test
curl http://localhost:3000/health
curl http://localhost:3000/run/my-api/
Terminal window
# Multi-worker with load balancer
mik run --workers 4 --lb
# Or run as background instance
mik run --detach --name prod
mik ps # Check status
mik logs prod -f # Follow logs
mik stop prod # Stop when done
Terminal window
git clone https://github.com/user/my-api.git
cd my-api
mik sync # Download all dependencies
mik build -rc
mik dev # Start development