aboutsummaryrefslogtreecommitdiff
path: root/src/api/hello-param.zig
blob: ba798af05ce7b3e284ddb4b0bb4469fa16c61c80 (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 .bad_request(.string("parameter needs to be an int"));

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