From 9fda8bbb279ea952dd6cd2cda56d121dbee67e49 Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Fri, 13 Jan 2023 11:15:42 +0100 Subject: [PATCH] added hello2 example --- examples/hello2/hello2.zig | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 examples/hello2/hello2.zig diff --git a/examples/hello2/hello2.zig b/examples/hello2/hello2.zig new file mode 100644 index 0000000..b4e674f --- /dev/null +++ b/examples/hello2/hello2.zig @@ -0,0 +1,45 @@ +const std = @import("std"); +const zap = @import("zap"); + +fn on_request(r: zap.SimpleRequest) void { + const m = r.method orelse ""; + const p = r.path orelse "/"; + const qm = if (r.query) |_| "?" else ""; + const qq = r.query orelse ""; + + std.debug.print(">> {s} {s}{s}{s}\n", .{ m, p, qm, qq }); + + if (r.body) |the_body| { + std.debug.print(">> BODY: {s}\n", .{the_body}); + } + + _ = r.sendBody( + \\ + \\

Hello from ZAP!!!

+ \\
+ \\
+ \\
+ \\
+ \\ + \\ + \\
+ \\ + ); +} + +pub fn main() !void { + var listener = zap.SimpleHttpListener.init(.{ + .port = 3000, + .on_request = on_request, + .log = false, + }); + try listener.listen(); + + std.debug.print("Listening on 0.0.0.0:3000\n", .{}); + + // start worker threads + zap.start(.{ + .threads = 2, + .workers = 2, + }); +}