liveBook · Manning

WIT

As explained in Server-Side WebAssembly

A WIT definition is a WIT description of the types and interfaces required to specify interactions between WebAssembly components.

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

How Server-Side WebAssembly covers it

How deep it goes
Explains WIT types, Canonical ABI marshaling, packages, interfaces, worlds, imports, exports, componentization, and generated bindings.
Examples
Uses Hello World, a SmartCMS key-value store, generated WASI CLI and library worlds, and an Ollama story-generation provider.
What it assumes
Introduces WIT from Wasm’s simple numeric types and linear memory rather than assuming prior interface-definition knowledge.
What you can do after
Build it from scratch by defining WIT interfaces and worlds, then importing capabilities and exporting component behavior.
How it connects
Connects WIT with the Wasm Component Model, Canonical ABI, linear memory, WASI, wasmCloud, and wit-bindgen.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Server-Side WebAssembly. The section links point to the parts of the book it draws on.