# Add API Route

> Adds a Fastify route to the Saltmarsh Booking API with its schema, auth level, repository call, and registration. Use when asked to "add an endpoint", "add a route", or "expose this over the API".

- Skill: `tuyv/add-api-route` (Agent Skill, multi-file: 3 files)
- Install (CLI): `npx get-skill add tuyv/add-api-route`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tuyv/add-api-route/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: tuyv (https://skillmd.com/u/tuyv)
- Updated: 2026-11-14
- Page: https://skillmd.com/skills/tuyv/add-api-route

---


# Add an API Route

1. Add the request and response schemas to `packages/shared/src/schemas/<resource>.ts`.
2. Create or extend `packages/api/src/routes/<resource>.ts`. Export a Fastify plugin.
3. Set `config.auth` to `"guest"`, `"owner"`, or `"public"`, and `config.rateLimit` if 60 a minute is wrong for this route.
4. Call a repository in `packages/api/src/repos`. Add the query there if it does not exist.
5. Register the plugin in `packages/api/src/app.ts`.
6. Add a typed call for it to `packages/web/src/lib/api.ts` if the web app will use it.

## Gotchas

- An owner route checks that the campsite in the path belongs to `request.owner.id`. The auth level alone does not do that.
- Return errors with `problem()`. A thrown error becomes a 500 with no detail.

