zigly
A Zig library for building Fastly Compute services.
Why Zig?
Fastly Compute bills based on execution time and memory usage. The Zig compiler produces WebAssembly modules that are exceptionally small, fast, and memory-efficient, often significantly smaller than equivalent Rust code, and orders of magnitude smaller than JavaScript bundles.
This translates directly to lower costs: smaller binaries mean faster cold starts, less memory overhead, and reduced execution time.
Quick Example
const zigly = @import("zigly");
pub fn main() !void {
var downstream = try zigly.downstream();
// Proxy to origin
try downstream.proxy("origin", "api.example.com");
// Or build a custom response
// try downstream.response.setStatus(200);
// try downstream.response.body.writeAll("Hello from the edge!");
// try downstream.response.finish();
}
Installation
Add the dependency:
zig fetch --save=zigly https://github.com/jedisct1/zigly/archive/refs/tags/0.1.14.tar.gz
In build.zig:
const zigly = b.dependency("zigly", .{
.target = target,
.optimize = optimize,
});
const exe_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe_module.addImport("zigly", zigly.module("zigly"));
exe_module.linkLibrary(zigly.artifact("zigly"));
const exe = b.addExecutable(.{
.name = "my_app",
.root_module = exe_module,
});
b.installArtifact(exe);
Target wasm32-wasi:
const target = b.standardTargetOptions(.{
.default_target = .{ .cpu_arch = .wasm32, .os_tag = .wasi }
});
Build with zig build -Doptimize=ReleaseSmall.
Documentation
See docs/index.md for full documentation including:
- Getting started guide
- API reference for all modules (HTTP, caching, rate limiting, geolocation, device detection, etc.)
- Practical guides and examples
- Deployment instructions
Requirements
- Zig 0.16.0 or later
- Local testing: Viceroy or Fastlike
- Fastly CLI for deployment
License
See the repository for license information.
