Skip to content
xucklessPublic

About

Anole is a Zig Framework for building backends: one server core that will serve REST, WebSockets, WebTransport and gRPC (over HTTP/1.1, HTTP/2 and HTTP/3), with TLS and auth built in. I have plans to wrap this into a Python and Node library too.

Topics

Resources

Security policy

Stars

19 stars

Watchers

0 watching

Forks

Repository files navigation

Anole

A backend framework for Zig, and a native server engine for Node and Python

Latest release CI Zig 0.17 License: MIT

Docs · Getting started · API reference · From Fiber · Changelog

Requirements

  • Zig 0.17.x. Nothing else: Zig compiles every C dependency.
  • Linux for production, macOS for development. Windows builds and passes its tests, but isn't tuned (what it lacks).

Quick start

Get the anole CLI from the latest release (Linux, macOS, Windows; check it against SHA256SUMS), then:

anole new my-api          # templates: minimal, rest-postgres, realtime, grpc, full
cd my-api && zig build run
curl localhost:3000/      # {"hello":"world"}, OpenAPI page at /docs

Or by hand, in a zig init project:

zig fetch --save git+https://github.com/xuckless/anole#v0.7.0
// build.zig
pub fn build(b: *@import("std").Build) void {
    _ = @import("anole").addApp(b, .{ .name = "api", .root_source_file = b.path("src/main.zig") });
}
// src/main.zig
const std = @import("std");
const anole = @import("anole");

fn hello(_: *anole.Request, res: *anole.Response) !void {
    res.body = "Hello, World!";
}

pub fn main(init: std.process.Init) !void {
    var app = try anole.App.init(init.gpa, .{});
    defer app.deinit();
    app.get("/", hello);
    try app.listen(":3000"); // Ctrl-C drains and stops
}

Templates · Getting started walks on to JSON, WebSockets, TLS, gRPC and deployment.

What Anole offers

Every protocol goes through one Anole core, which reaches databases, messaging, storage and email; auth, TLS and observability sit underneath

One router, one runtime, one line per feature:

HTTP HTTP/1.1, HTTP/2 and HTTP/3 on one router, static files, TLS with hot reload · routing · server
Realtime WebSockets with rooms, WebTransport, server-sent events with replay · WebSocket · WebTransport · SSE
gRPC server and client, gRPC-Web, Connect, JSON transcoding · gRPC
Auth JWT/JWKS, OIDC, sessions, CSRF, API keys, RBAC, rate limits · auth
Data PostgreSQL, SQLite, MongoDB, Redis/Valkey; request deadlines, coalescing, caches · databases
Connectors NATS, Kafka, S3-compatible storage, SMTP · messaging · storage · email
Background durable jobs, cron, signed webhooks in and out · jobs · cron · webhooks
Raw sockets TCP and UDP servers on the same runtime · net
Clients HTTP/1.1, /2 and /3 with retries and circuit breakers · clients
DX typed config and .env, validation, OpenAPI, in-memory tests, a live console · config · validation · testing · console
Ops Prometheus, OpenTelemetry, health checks, graceful drain, zero-downtime restarts, AWS Lambda · observability · Lambda
Node, Python a C ABI for anole-node and anole-py (in progress) · C ABI

Performance

HttpArena v0.5.0 composite ranks: gRPC 3rd of 12, Gateway 3rd of 10, HTTP/3 4th of 22, HTTP/2 7th of 38, WebSocket 7th of 42, HTTP/1.1 9th of 102

Ranks from HttpArena, an independent benchmark, among all its entries (run saved in PR #1692). My own harness: bench/.

Build flags

Every bundled library sits behind a flag, all on by default; what you switch off is never downloaded. -Dprofile=minimal|web|full sets them at once, single flags override it (.features = .{ .kafka = false } with addApp). Hello, World is about 1.3 MB minimal, 6 MB full.

All flags
Flag minimal web full (default) Adds
-Dtls=boringssl|none none boringssl boringssl BoringSSL
-Dhttp2=bool false true true HTTP/2 server and client (Zig, no C library)
-Dhttp3=bool false false true ngtcp2, nghttp3, WebTransport
-Dcompression=bool false true true zlib-ng, zstd
-Dbrotli=bool false true true Brotli responses (google/brotli); needs -Dcompression
-Dlibdeflate=bool false true true libdeflate for buffered gzip responses; needs -Dcompression
-Dgrpc=bool false false true gRPC, zig-protobuf (and protoc for codegen)
-Dwebsocket=bool false true true WebSocket
-Dauth=bool false true true JWT, OIDC, CSRF, passwords, API keys, RBAC
-Djson=bool false true true yyjson
-Dredis=bool false false true hiredis (Redis/Valkey client, stores)
-Dpostgres=bool false true true PostgreSQL client (pg.zig fork)
-Dsqlite=bool false true true SQLite (amalgamation, zig-sqlite fork)
-Dmongodb=bool false false true MongoDB client and BSON
-Dopenapi=bool false true true OpenAPI 3.1 documents and the docs page (pure Zig)
-Dnats=bool false false true NATS client (pure Zig)
-Dkafka=bool false false true Kafka client, lz4; needs -Dcompression
-Dconsole=bool false true true the live console (control socket and terminal UI)
-Dnet=bool false true true raw TCP and UDP servers (pure Zig)
-Djobs=bool false true true durable jobs and cron (pure Zig)
-Dwebhooks=bool false true true webhooks out and the verify middleware; needs -Djobs
-Ds3=bool false true true S3-compatible object storage client (pure Zig)
-Dsmtp=bool false true true SMTP client for sending mail (pure Zig)
-Dlambda=bool true true true the AWS Lambda adapter (pure Zig)

gRPC needs HTTP/2, HTTP/3 needs TLS, Brotli/libdeflate/Kafka need compression, webhooks need jobs; asking for one without the other is an error.

Develop

zig build test          # unit and smoke tests
zig build test-flags    # every preset and flag combination
zig build run-full      # every listener: 8080 (h1, h2c), 8443 (TLS, h2, h3)
zig build docs          # API reference in zig-out/docs

Examples run with zig build run-<name>: hello, rest, websocket, grpc, auth, postgres, sqlite, mongodb, redis, net, io, lambda, full.

Status

Pre-1.0; the latest release is 0.7.0, and the API may still change. Next: performance fixes in 0.7.1 and 0.7.2, then 1.0.0-rc.1; the anole-node and anole-py bindings alongside.

Anole stands on zio, dusty (adapted as its HTTP core), nghttp2 (its HTTP/2 rules, translated to Zig), ngtcp2, nghttp3 and BoringSSL. Bugs and ideas: Issues; questions: Discussions; security: SECURITY.md.

License

MIT. Bundled components are MIT, Apache-2.0, Zlib or BSD, listed in THIRD_PARTY_NOTICES.

About

Anole is a Zig Framework for building backends: one server core that will serve REST, WebSockets, WebTransport and gRPC (over HTTP/1.1, HTTP/2 and HTTP/3), with TLS and auth built in. I have plans to wrap this into a Python and Node library too.

Topics

Resources

Security policy

Stars

19 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages