aboutsummaryrefslogtreecommitdiff
path: root/src/api/hello-body.zig
blob: 2e5a09e9d93f2896fa1ef91caab2f6fbee8b0f5c (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 .bad_request(.void);

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