# Add API Endpoint

> Add a new API endpoint following project conventions (Zod, route registration, client, tests). Use when creating or extending backend API routes. Use when this capability is needed.

- Skill: `tomevault-io/add-api-endpoint` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/add-api-endpoint`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/add-api-endpoint/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/add-api-endpoint

---


# Add API Endpoint

Use this skill when adding a new REST endpoint to TikTok-AI-Agent.

## Steps

1. **Route** – Create or edit a file in `apps/server/src/routes/`. Implement the handler (e.g. `router.get/post('/...', async (req, res) => { ... })`).
2. **Zod** – Define a schema for body and, if needed, params. Use `safeParse()` on `req.body` / `req.params`. Return `400` with `{ error, details: parsed.error.flatten() }` on failure. For `runId`, `projectId`, `planVersionId`, use `z.string().uuid()`.
3. **Register** – Mount the router in `apps/server/src/index.ts` under `/api/...`.
4. **Client** – Add a function in `apps/web/src/api/client.ts` and update `api/types.ts` if needed.
5. **Test** – Add or extend an integration test in `apps/server/tests/` or E2E in `apps/web/tests/e2e/`.

## Rules

- Do not leave TODOs, placeholders, or dummy code.
- Use `try/catch` for DB and external calls; return 5xx JSON on failure.
- Wrap `JSON.parse` in try/catch. Use `.strict()` on body schemas.

## References

- [apps/server/src/routes/project.ts](apps/server/src/routes/project.ts), [plan.ts](apps/server/src/routes/plan.ts)
- [.cursor/rules/api-routes.mdc](.cursor/rules/api-routes.mdc)

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/sedarged) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-13 -->

