diff --git a/build.zig b/build.zig index 7319e09..3642a97 100644 --- a/build.zig +++ b/build.zig @@ -19,7 +19,7 @@ pub fn build(b: *std.build.Builder) !void { src: []const u8, }{ .{ .name = "hello", .src = "examples/hello/hello.zig" }, - // .{ .name = "routes", .src = "examples/routes/routes.zig" }, + .{ .name = "routes", .src = "examples/routes/routes.zig" }, // .{ .name = "serve", .src = "examples/serve/serve.zig" }, }) |excfg| { const ex_name = excfg.name; diff --git a/examples/routes/routes.zig b/examples/routes/routes.zig new file mode 100644 index 0000000..dc62312 --- /dev/null +++ b/examples/routes/routes.zig @@ -0,0 +1,61 @@ +const std = @import("std"); +const zap = @import("zap"); + +fn dispatch_routes(r: zap.SimpleRequest) void { + // dispatch + if (r.path) |the_path| { + if (routes.get(the_path)) |foo| { + foo(r); + } + } + // or default: present menu + _ = r.sendBody( + \\ + \\
+ \\ + \\ + \\ + \\ + ); +} + +fn static_site(r: zap.SimpleRequest) void { + _ = r.sendBody("