aboutsummaryrefslogtreecommitdiff
path: root/src/api/hello-param.zig
blob: f4de1dd68b22f1e33bb0470ac4fcad688dc8bbea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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 .badRequest(.string("parameter needs to be an int"));

    return .okOrError(.json(request.arena, .{ .value = value, }));
}