aboutsummaryrefslogtreecommitdiff
path: root/src/api/hello-body.zig
blob: 43afb872c5b0f8c37e1ee3909d7f0dd87b0b9fd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 .badRequest(.void);

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