diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-06-06 10:35:14 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-06-06 10:35:14 +0200 |
| commit | 1d6e34388d9d792fd184c8b9e0fb11fb9b7e14f9 (patch) | |
| tree | 2eaaf5077c604c79a359037c772f99bb83839545 /src/api/hello-body.zig | |
| parent | f39dfd01ab06cf92a3bcad75fcb175a8242ec1b1 (diff) | |
api: add example implementations
Diffstat (limited to 'src/api/hello-body.zig')
| -rw-r--r-- | src/api/hello-body.zig | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/api/hello-body.zig b/src/api/hello-body.zig new file mode 100644 index 0000000..2e5a09e --- /dev/null +++ b/src/api/hello-body.zig @@ -0,0 +1,20 @@ +const http = @import("http"); +const Context = http.handler.Context; +const Response = http.Response; + +const Ctx = Context(.{"hello-body"}); +pub const ctx: Ctx = .{ + .post = post, +}; + +const Body = struct { + value: usize, +}; + +fn post(request: Ctx.Request) Response { + const body = request.json(Body) catch return .bad_request(.void); + + return .ok_or_error(.json(request.arena, .{ + .value = body.value, + })); +} |