Skip to content

commandBackend and APIs

Add Endpoint

Adds a new API endpoint that matches your existing routes, with validation, error handling, tests and docs in one pass.

npx workspacetemplates add add-endpoint --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/add-endpoint.md16 lines · 1.2 KBFile
---
description: Adds a new API endpoint that matches your existing routes, with validation, error handling, tests and docs in one pass.
argument-hint: "[method path and what it does]"
---

Add this endpoint to the project: $ARGUMENTS

1. Find the closest existing endpoint with `grep` or the route table. Read its handler, schema, service call, test and doc entry. Copy that structure exactly: folder, naming, auth middleware, response envelope.
2. State a short plan: method, path, auth, input fields with types, success status, and each error status. Ask one question if the request is ambiguous, otherwise continue.
3. Write the handler thin. Put business logic in the layer the project already uses for it.
4. Validate every input with the project's own validator. Return the same error shape as other routes (400 for bad input, 401 or 403 for auth, 404 for missing, 409 for conflicts).
5. Add tests: one success case, one case per error status, one for bad input.
6. Update the route list, OpenAPI file or README section if one exists.
7. Run the test suite and the linter. Fix what you broke.

Report the files changed, the final request and response examples, and anything you guessed. Do not touch unrelated routes or run migrations without asking first.

What it does

A new endpoint is rarely just a handler. It needs input checks, error shapes that match the rest of the API, tests and a line in the docs. This command finds how your project already does each of those and repeats the pattern.

It starts by reading a neighboring endpoint, so the new route lands in the right folder with the same naming, auth and response envelope. It shows the plan before it writes anything.

Example

you › /add-endpoint GET /projects/:id/members, returns paginated members, owners only

agent › Plan: GET /projects/:id/members, owner auth, query page and limit, 200 with {items,total}, 403 for non-owners, 404 for unknown project.
Added src/routes/projects/members.ts, schema and 5 tests (all passing). Updated docs/api.md.
Assumption: members sorted by joinedAt descending.

Questions

How does it know my conventions?
It reads the nearest similar route first and mirrors its layout, middleware and error format instead of using generic defaults.
Will it create database tables?
No. If the endpoint needs a schema change, it stops and asks, because migrations are hard to undo.
  • Add Caching

    CommandBackend and APIs

    Free
  • Add Health Check

    CommandBackend and APIs

    Free
  • Add Pagination

    CommandBackend and APIs

    Free
  • Add Rate Limit

    CommandBackend and APIs

    Free