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-param.zig | |
| parent | f39dfd01ab06cf92a3bcad75fcb175a8242ec1b1 (diff) | |
api: add example implementations
Diffstat (limited to 'src/api/hello-param.zig')
| -rw-r--r-- | src/api/hello-param.zig | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/api/hello-param.zig b/src/api/hello-param.zig new file mode 100644 index 0000000..ba798af --- /dev/null +++ b/src/api/hello-param.zig @@ -0,0 +1,14 @@ +const http = @import("http"); +const Context = http.handler.Context; +const Response = http.Response; + +const Ctx = Context(.{ "hello-param", .value }); +pub const ctx: Ctx = .{ + .get = get, +}; + +fn get(request: Ctx.Request) Response { + const value = request.params.value.as(usize) catch return .bad_request(.string("parameter needs to be an int")); + + return .ok_or_error(.json(request.arena, .{ .value = value, })); +} |