WASI HTTP (experimental)
On this page
WASI HTTP packaging and host compatibility are still evolving. Test the component on your intended host before deployment.
--target wasi-http turns a webroot directory into one .wasm component that exports the WASI HTTP incoming handler. The component serves the same files and templates as matchbox --serve, with the webroot embedded in the binary.
This is different from --target wasi, which packages a single script that runs once and exits.
Build
matchbox --target wasi-http --webroot ./site --output site.wasm
| Flag | Default | Meaning |
|---|---|---|
--webroot <dir> | . | Directory to package. |
--output <file> | <webroot>.wasm | Output file. |
--webroot and --output are the only flags this target reads. Nothing is listening after the build; the component is run by a host that supports WASI HTTP.
The build:
- Reads
boxlang.jsonfrom the webroot forrewritesandrewriteFileName. Awebsocketblock is ignored and the build prints a warning. - Compiles every
.bxmand.bxsfile in the webroot. A syntax error stops the build. - Embeds every file under the webroot, including
boxlang.json, together with the compiled templates. - Patches that payload into a prebuilt
matchbox_wasi_http_runnercomponent and writes the result.
Limits
| Limit | Detail |
|---|---|
| Size | The payload must fit in a 4 MiB region of the runner (4 MiB minus 12 bytes). A larger webroot fails with "exceeds the embed capacity". Every file in the directory counts, so keep build output, node_modules and similar out of the webroot. |
| Native code | The build fails if the webroot has a native directory, a boxlang_modules/*/native directory, or a .bx, .bxm or .bxs file that contains the text java: or rust:. |
| WebSockets | Not supported. |
| Sessions | Kept in memory of the running instance. They are not shared between instances and are lost when the instance stops. |
Behavior
The component runs the same engine as the webroot server, so these rules apply unchanged:
GET,HEADandPOSTare handled; other methods return405..bxmand.bxsfiles are rendered as templates, and a directory is answered by itsindex.bxmorindex.bxs.- Path segments that start with
.return403. - The
url,form,cookie,sessionandcgiscopes are populated as described in Web server.
Differences from --serve:
- Requests are read from the WASI HTTP request, so a POST body with
application/x-www-form-urlencodedis available inform. - A failure in the engine returns
500with the error text astext/plain. HEADresponses carry no body.
Requirements
The CLI builds the runner component when it is not already present. It looks for target/wasm32-wasip2/release/matchbox_wasi_http_runner.wasm inside the MatchBox source tree it was compiled from, and otherwise runs
cargo build --release --target wasm32-wasip2 -p matchbox_wasi_http_runner
in that tree. The build therefore needs the source checkout, a Rust toolchain and the target (rustup target add wasm32-wasip2). A CLI downloaded as a release binary cannot find that tree unless the checkout exists at the path it was built from.
The component's exported interface is wasi:http/incoming-handler (the proxy world of the wasi crate). Use a host that implements it to run the file.