Skip to content

Shopify/shopify-function-wasm-api

Repository files navigation

Shopify Function Wasm API

A high-performance API for building Shopify Functions using WebAssembly (Wasm).

Architecture

The Wasm API consists of these main components:

  1. Provider (provider/)

    • Implements low-level Wasm operations for:
      • Reading function input
      • Serializing the function output
  2. Core (core/)

    • Defines common types used by the providers and api
  3. API (api/)

    • Provides a high-level interface for interacting with the provider
    • Abstracts away low-level Wasm details
    • Includes examples and documentation
  4. 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

Getting Started

Prerequisites

  • Rust (latest stable version)

Basic Usage

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.

Documentation

For more detailed documentation, refer to:

Contributing

Contributions are welcome! Please read our Contributing Guide and Code of Conduct before submitting a pull request.

License

This project is licensed under the MIT License.