aboutsummaryrefslogtreecommitdiff
path: root/src/api/hello-param.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/hello-param.zig')
-rw-r--r--src/api/hello-param.zig14
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, }));
+}