A Zig HTTP/1.1 server framework built directly on Linux io_uring.
const std = @import("std");
const zeemo = @import("zeemo");
pub fn main() !void {
var dba: std.heap.DebugAllocator(.{}) = .init;
defer _ = dba.deinit();
const gpa = dba.allocator();
var server = zeemo.Server.init(gpa, .{ .port = 8080 });
defer server.deinit();
try server.get("/hello", hello);
try server.get("/echo/:name", echo);
try server.get("/json", jsonExample);
try server.run();
}
fn hello(_: *const zeemo.Request, res: *zeemo.Response) !void {
try res.text("Hello, World!");
}
fn echo(req: *const zeemo.Request, res: *zeemo.Response) !void {
const name = req.paramStr("name") orelse "stranger";
try res.printText("hi {s}", .{name});
}
fn jsonExample(_: *const zeemo.Request, res: *zeemo.Response) !void {
try res.json(.{ .ok = true, .version = "0.1.0" });
}io_uringevent loop — multishot accept, fork-workers pinned to CPUs viasched_setaffinity,SO_REUSEPORTfor kernel-side load balancing. Each worker is a shared-nothing process.- Hand-written HTTP/1.1 parser —
Content-LengthandTransfer-Encoding: chunkedbodies, keep-alive, pipelining, robust to TCP fragmentation across recv calls. - Pipelined response batching —
drainAndSendconcatenates multiple pipelined responses into onesend()syscall. - Generic comptime JSON serializer —
res.json(value)walks the value's type via@typeInfoand writes JSON per request. Works on structs, slices, arrays, optionals, primitives. - Static file serving —
zeemo.static.Dirloads files at startup and pre-bakes the full HTTP response for each variant (uncompressed,.br,.gz). The handler dispatches the right slice based onAccept-Encoding. - Configurable buffers —
Server.Configexposesparser_header_buf,parser_body_buf,write_inline_bytesso applications can size for their workload (small request/response services vs. upload-heavy ones).
Used as the engine of the HttpArena
zeemo
(engine-category) entry, currently ranked #1 on baseline-4096 and
json-4096 (composite-with-mem). Powers the zeemo-tuned
(tuned-category) entry — the first Zig tuned-category entry on HttpArena.
Linux-only. Built and tested against Zig 0.16.
zig fetch --save 'https://github.com/skylightis666/zeemo/archive/main.tar.gz'Then in build.zig:
const zeemo_dep = b.dependency("zeemo", .{
.target = target,
.optimize = optimize,
});
exe_mod.addImport("zeemo", zeemo_dep.module("zeemo"));examples/hello_world/— minimal 3-endpoint demoexamples/httparena-tuned/— full HttpArena tuned-category submission with baseline / pipelined / limited-conn / json / static profiles
zig test src/lib.zig # library unit tests
zig build run-hello # local smoke test