prefect server in zig

web server#

uses zap (facil.io bindings) for http.

route dispatch#

single routes.handle() function dispatches by path prefix:

if (std.mem.startsWith(u8, target, "/api/flows"))
    try flows.handle(r);

each resource module handles its own method/path matching internally.

resource handlers#

pattern from python prefect: each resource (flows, flow_runs, task_runs) has:

  • handle(r) - top-level dispatch
  • internal functions for create/read/update operations
  • arena allocator per request for response formatting

response helpers#

common pattern across handlers:

fn sendJson(r: zap.Request, body: []const u8) void { ... }
fn sendJsonStatus(r: zap.Request, body: []const u8, status: StatusCode) void { ... }

cors#

preflight handled at route dispatch level - returns 204 with allow headers.