agentleFS
tejastn10tejastn10/workbench/skills/design/design-endpoint/SKILL.md

design-endpoint

Skill1 starsChanged 2 months agoMITView on GitHub

Design a REST (or RPC) endpoint before implementing — resource and verb, request/response shape, status codes, pagination, filtering, idempotency, versioning under a v1/ folder, and auth. Use when adding an API, when asked to "design the endpoint / API", or before writing a NestJS controller.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every endpoint states its authz rule — not just "authenticated" but "allowed to touch *this* resource" (no IDOR).

    line 47

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Design an endpoint

Design the contract first — it's the expensive thing to change later (design/evolve-contract).

Shape

  • Resource, not action — POST /users/:id/deactivations over POST /users/:id/deactivate where it's natural; pragmatic RPC-style verbs are fine for genuine operations. Be consistent within the service.
  • Verb semantics — GET safe + idempotent, PUT/DELETE idempotent, POST not. PATCH for partial update with a defined merge semantics.
  • Request body — a DTO with validation (class-validator for NestJS). Reject unknown fields or ignore them — pick one and document it. snake_case at the wire layer, don't mix.
  • Response — return the resource (or the entity) directly; don't wrap every response in a new envelope class just for this endpoint. Consistent error shape across the service.
  • Status codes — 200/201/204, 400 (validation), 401 vs 403, 404, 409 (conflict / idempotency), 422 (semantic), 429. Don't invent.
  • Idempotency — for non-idempotent POST that a client may retry, accept an Idempotency-Key and dedup.

Collections

  • Pagination — cursor/keyset for anything that grows (?cursor=…&limit=…), not offset. Return the next cursor. Cap and default limit.
  • Filtering / sorting — a small allowlist of fields, documented. Don't accept arbitrary query expressions.
  • Sparse fields / expansion — only if there's a real need.

Versioning & rollout

  • Live under v1/ from day one (NestJS: v1/controllers, v1/dto, v1/services). A breaking change becomes v2/, not an edit — see design/evolve-contract.
  • New public route → added to the RBAC / gateway allowlist in all envs, loop in the platform owner, before it ships.

Auth

  • Every endpoint states its authz rule — not just "authenticated" but "allowed to touch this resource" (no IDOR).
  • Rate limit where abuse is possible.

Output

The path + verb, the request DTO, the response shape, the status codes, the authz rule, pagination/filter design. Then hand to design/scaffold-nestjs-module to build it.

Anti-patterns

  • ❌ A new response-wrapper class per endpoint.
  • ❌ offset pagination on a growing collection.
  • ❌ Arbitrary query-language filters.
  • ❌ Inventing status codes, or 200 for everything.
  • ❌ No v1/, so the first breaking change has nowhere to go.
  • ❌ Authz that only checks "logged in".

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.