From e238a5d9ea46ce1b0356c33a0b4440b7a98d0e5b Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Thu, 12 Jan 2023 11:21:09 +0100 Subject: [PATCH] improved hello example --- examples/hello/hello.zig | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/examples/hello/hello.zig b/examples/hello/hello.zig index 13f4545..fd5dbc2 100644 --- a/examples/hello/hello.zig +++ b/examples/hello/hello.zig @@ -1,27 +1,17 @@ const std = @import("std"); const zap = @import("zap"); -fn on_request(request: [*c]zap.C.http_s) callconv(.C) void { - std.debug.print("GOT A REQUEST!\n", .{}); - // std.time.sleep(5 * 1000 * 1000); - _ = zap.sendBody(request, "Hello from ZAP!!!"); +fn on_request(r: [*c]zap.C.http_s) callconv(.C) void { + _ = zap.sendBody(r, "

Hello from ZAP!!!

"); } pub fn main() !void { - // std.debug.print("debug1\n", .{}); - // configure - var listen_settings: zap.ListenSettings = .{}; - // std.debug.print("debug2\n", .{}); - listen_settings.on_request = on_request; - listen_settings.log = true; - - // std.debug.print("debug3\n", .{}); - // listen - try zap.listen("3000", null, listen_settings); - std.debug.print("Listening on port 3000\n", .{}); - - // std.debug.print("debug4\n", .{}); + try zap.listen("3000", null, .{ + .on_request = on_request, + .log = true, + }); + std.debug.print("Listening on 0.0.0.0:3000\n", .{}); // start working zap.start(.{