Get ID from route

This commit is contained in:
jaina heartles 2022-07-10 17:40:17 -07:00
parent b738a02e16
commit 470fa50bb1

View file

@ -10,7 +10,7 @@ const RouteArgs = http.RouteArgs;
const router = Router{
.routes = &[_]Route{
Route.new(.GET, "/healthcheck", healthcheck),
Route.new(.GET, "/", getNote),
Route.new(.GET, "/:id", getNote),
},
};
@ -44,8 +44,9 @@ fn respondJson(ctx: *http.server.Context, value: anytype, alloc: std.mem.Allocat
try stream.finish();
}
fn getNote(srv: *RequestServer, ctx: *http.server.Context, _: RouteArgs) !void {
const note = try srv.db.getNote("1", srv.alloc);
fn getNote(srv: *RequestServer, ctx: *http.server.Context, args: RouteArgs) !void {
const id = args.get("id").?;
const note = try srv.db.getNote(id, srv.alloc);
defer db.free(srv.alloc, note);
try respondJson(ctx, note, srv.alloc);