Add API Endpoint
Use this skill when adding a new REST endpoint to TikTok-AI-Agent.
Steps
- •Route – Create or edit a file in
apps/server/src/routes/. Implement the handler (e.g.router.get/post('/...', async (req, res) => { ... })). - •Zod – Define a schema for body and, if needed, params. Use
safeParse()onreq.body/req.params. Return400with{ error, details: parsed.error.flatten() }on failure. ForrunId,projectId,planVersionId, usez.string().uuid(). - •Register – Mount the router in
apps/server/src/index.tsunder/api/.... - •Client – Add a function in
apps/web/src/api/client.tsand updateapi/types.tsif needed. - •Test – Add or extend an integration test in
apps/server/tests/or E2E inapps/web/tests/e2e/.
Rules
- •Do not leave TODOs, placeholders, or dummy code.
- •Use
try/catchfor DB and external calls; return 5xx JSON on failure. - •Wrap
JSON.parsein try/catch. Use.strict()on body schemas.