Add the API route described here: $ARGUMENTS
If the method, path or behaviour is unclear, ask one short question before writing code.
Steps
- Read
src/app/api/links/route.ts,src/lib/http.tsandsrc/lib/links/schema.tsto match the existing patterns. Do not invent a new error format. - Put input validation in a Zod schema in the relevant
src/lib/<domain>/schema.ts, not inline in the route. - Put data access in
src/lib/<domain>/store.ts. The route handler only parses, calls the store, and maps results to responses. - Create
src/app/api/<path>/route.ts:export const dynamic = "force-dynamic";- Malformed JSON →
errorResponse(400, "invalid_json") ZodError→validationError(err)- Not found →
errorResponse(404, "not_found") - Dynamic segments:
{ params }: { params: Promise<{ id: string }> }andawait params.
- Write
route.test.tsnext to the route. UseuseTempDataFile()from@/test/temp-data-fileand call the exported handlers withnew Request(...). Cover: success, each validation failure class, not found, and malformed JSON where a body is accepted. - Run
npx vitest run <the new test file>, thennpm run check, thennpm run build. - Report: the endpoint contract (method, path, request body, responses with status codes) and the commands you ran with their result.