WebAssembly Interface Types (WIT) is a language-agnostic interface definition language for describing how Wasm components, hosts, and other guests communicate. It replaces fragile agreements about linear-memory layouts with named interfaces and higher-level types, while the Canonical ABI marshals values across the Wasm boundary. section 2.4 section 3.0
A WIT definition can describe:
- Primitive interface values such as bool, signed and unsigned integers, floats, char, and string. section 2.4
- Structured values including list, option, result, and tuple. section 2.4
- A package, interfaces, and a world that declares imports supplied by a host and exports implemented by a guest. section 3.4.1
A key-value-store contract
Define get and set in a kvstore interface, then import that interface into an app world. The host supplies storage, while the guest exports run as its entry point. This separates the capability implementation from component behavior. section 3.4.1
Listing 3.5 The updated WIT file for our key-value store (smart_cms.wit)
package component:smartcms;
interface kvstore { #1
get: func(key: string) -> string;
set: func(key: string, value: string);
}
world app {
import kvstore; #2
export run: func() -> string; #3
}
Inspect a complete WIT file that packages the key-value interface and app world together. section 3.4.1
WIT is the interface language of the Wasm Component Model. Tooling can use a WIT file to link a guest correctly when componentizing it, including capabilities the guest code alone does not reveal. Generated bindings can then expose imported interfaces to application code. section 3.0 section 3.2.3 section 6.6.2
Custom machine-learning capability
A custom Ollama interface defines request and response records, optional fields, and result-based errors for story generation. A component imports that interface and calls generated bindings, illustrating how a third-party provider can add a capability where wasi:nn lacks direct wasmCloud support. section 6.6.2
