Get ID from route
This commit is contained in:
parent
b738a02e16
commit
470fa50bb1
1 changed files with 4 additions and 3 deletions
|
@ -10,7 +10,7 @@ const RouteArgs = http.RouteArgs;
|
||||||
const router = Router{
|
const router = Router{
|
||||||
.routes = &[_]Route{
|
.routes = &[_]Route{
|
||||||
Route.new(.GET, "/healthcheck", healthcheck),
|
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();
|
try stream.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getNote(srv: *RequestServer, ctx: *http.server.Context, _: RouteArgs) !void {
|
fn getNote(srv: *RequestServer, ctx: *http.server.Context, args: RouteArgs) !void {
|
||||||
const note = try srv.db.getNote("1", srv.alloc);
|
const id = args.get("id").?;
|
||||||
|
const note = try srv.db.getNote(id, srv.alloc);
|
||||||
defer db.free(srv.alloc, note);
|
defer db.free(srv.alloc, note);
|
||||||
|
|
||||||
try respondJson(ctx, note, srv.alloc);
|
try respondJson(ctx, note, srv.alloc);
|
||||||
|
|
Loading…
Reference in a new issue