diff --git a/examples/endpoints/endpoints.zig b/examples/endpoints/endpoints.zig index a2d1c70..2885389 100644 --- a/examples/endpoints/endpoints.zig +++ b/examples/endpoints/endpoints.zig @@ -57,12 +57,12 @@ fn userIdFromPath(path: []const u8) ?usize { return null; } -pub fn getUser(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void { +fn getUser(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void { _ = e; if (r.path) |path| { if (userIdFromPath(path)) |id| { if (users.get(id)) |user| { - if (Users.stringify(user, .{})) |json| { + if (zap.stringify(user, .{})) |json| { _ = r.sendJson(json); } } @@ -70,13 +70,13 @@ pub fn getUser(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void { } } -pub fn listUsers(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void { +fn listUsers(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void { _ = e; var l: std.ArrayList(Users.User) = std.ArrayList(Users.User).init(alloc); if (users.list(&l)) {} else |_| { return; } - if (Users.stringifyUserList(&l, .{})) |maybe_json| { + if (zap.stringifyArrayList(Users.User, &l, .{})) |maybe_json| { if (maybe_json) |json| { _ = r.sendJson(json); } @@ -84,3 +84,16 @@ pub fn listUsers(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void { return; } } + +fn postUser(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void { + _ = e; + if (r.path) |path| { + if (userIdFromPath(path)) |id| { + if (users.get(id)) |user| { + if (zap.stringify(user, .{})) |json| { + _ = r.sendJson(json); + } + } + } + } +} diff --git a/examples/endpoints/html/index.html b/examples/endpoints/html/index.html index eb6d074..270c2c0 100644 --- a/examples/endpoints/html/index.html +++ b/examples/endpoints/html/index.html @@ -2,6 +2,6 @@
- +