-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.zig
More file actions
27 lines (20 loc) · 699 Bytes
/
main.zig
File metadata and controls
27 lines (20 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const std = @import("std");
const httpz = @import("httpz");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
var server = try httpz.Server(void).init(allocator, .{ .port = 8000 }, {});
defer {
server.stop();
server.deinit();
}
var router = server.router(.{});
router.get("/version", versionHandler, .{});
std.debug.print("listening on port 8000\n", .{});
try server.listen();
}
fn versionHandler(req: *httpz.Request, res: *httpz.Response) !void {
std.log.info("{any} {s}", .{ req.method, req.url.path });
res.status = 200;
try res.json(.{ .version = "0.0.1" }, .{});
}