http-wasm-guest 0.9.1

A Rust library for implementing HTTP-Wasm guest handlers.
Documentation

http-wasm Guest Library

This library provides a Rust implementation for the Wasm Guest ABI and interfaces with http-wasm.

It is designed for writing Traefik plugins in Rust, and works with any http-wasm compatible runtime.

Design Goals

  • Minimal dependency footprint: only the log crate is required at runtime.
  • Low-level Byte abstraction to enable all use-cases.
  • Memory-efficient data handling to suit constrained Wasm environments.

Credits

Usage

Add the dependency to your project:

cargo add http-wasm-guest

Implement the Guest trait and register the plugin. See the examples for complete code.

use http_wasm_guest::{Guest, Request, Response, register};

/// A minimal plugin that adds a custom header to each request.
struct Plugin;

impl Guest for Plugin {
    fn handle_request(&self, request: &Request, _response: &Response) -> (bool, i32) {
        let header = request.header();
        header.add(b"X-Bar", b"bar");
        (true, 0)
    }
}

/// Registers the plugin with the http-wasm runtime.
fn main() {
    let plugin = Plugin;
    register(plugin);
}

Build

Add the WASI target for building the plugin:

rustup target add wasm32-wasip1

Build the plugin with

cargo build --target wasm32-wasip1 --release

Deploy

Install your plugin

plugins/
└── src
    └── plugindemowasm
        └── plugin.wasm