Skip to content

skylightis666/zeemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zeemo

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" });
}

What it gives you

  • io_uring event loop — multishot accept, fork-workers pinned to CPUs via sched_setaffinity, SO_REUSEPORT for kernel-side load balancing. Each worker is a shared-nothing process.
  • Hand-written HTTP/1.1 parserContent-Length and Transfer-Encoding: chunked bodies, keep-alive, pipelining, robust to TCP fragmentation across recv calls.
  • Pipelined response batchingdrainAndSend concatenates multiple pipelined responses into one send() syscall.
  • Generic comptime JSON serializerres.json(value) walks the value's type via @typeInfo and writes JSON per request. Works on structs, slices, arrays, optionals, primitives.
  • Static file servingzeemo.static.Dir loads files at startup and pre-bakes the full HTTP response for each variant (uncompressed, .br, .gz). The handler dispatches the right slice based on Accept-Encoding.
  • Configurable buffersServer.Config exposes parser_header_buf, parser_body_buf, write_inline_bytes so applications can size for their workload (small request/response services vs. upload-heavy ones).

Status

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.

Install

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

Tests

zig test src/lib.zig    # library unit tests
zig build run-hello     # local smoke test

About

Bare-metal Zig io_uring HTTP/1.1 server — HttpArena benchmark entry

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages