A high-performance API for building Shopify Functions using WebAssembly (Wasm).
The Wasm API consists of these main components:
-
Provider (
provider/
)- Implements low-level Wasm operations for:
- Reading function input
- Serializing the function output
- Implements low-level Wasm operations for:
-
Core (
core/
)- Defines common types used by the
providers
andapi
- Defines common types used by the
-
API (
api/
)- Provides a high-level interface for interacting with the provider
- Abstracts away low-level Wasm details
- Includes examples and documentation
-
Trampoline (
trampoline/
)- CLI tool that augments Wasm modules to interface with the provider
- Handles memory sharing between guest and provider modules
- Creates the necessary Wasm imports/exports
- Rust (latest stable version)
Here's a simple example of how to use the API:
fn main(context: &mut Context) -> Result<()> {
let input = context.input_get()?;
// Function logic
context.finalize_output()?;
Ok(())
}
To build a function example, create a new example and build it targeting wasm32-wasip1
:
cargo build --release --target wasm32-wasip1 -p shopify_function_wasm_api --example echo
The trampoline tool bridges communication between your Wasm module and the provider module. To trampoline your Wasm module:
# Short flags
cargo run -p shopify_function_trampoline -- -i input.wasm -o output.wasm
For examples, check out the examples directory.
For more detailed documentation, refer to:
Contributions are welcome! Please read our Contributing Guide and Code of Conduct before submitting a pull request.
This project is licensed under the MIT License.