agentleFS
willdadywilldady/platypus/.agents/skills/api-conventions/SKILL.md

api-conventions

Skill130 starsChanged 5 days agoMITView on GitHub

Response-body conventions for the Platypus backend API — the `error` key for failures, the `message` key for 2xx status messages, and when to throw a typed error instead of returning a response. Use when adding or changing a backend route or its tests.

11 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 7 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Never message on a 4xx/5xx — that is the one crossing the codebase does not make.

    line 18

“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “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

API Response Conventions

The two keys

error carries a failure. message carries a 2xx status line for an operation that has no resource to return.

return c.json({ error: "Workspace not found" }, 404);
return c.json({ message: "Board deleted" });

Never message on a 4xx/5xx — that is the one crossing the codebase does not make.

A delete or action with nothing to return answers 200 { message } — never a bodiless 204, and never { success: true }.

A failure body is { error } and nothing else: no success, no detail fields beside it. Three exceptions, each because a frontend client reads the extra shape:

FailureBodyWhy
Request validation400 { error: Issue[] }the form maps each issue's path onto its field
Agent promote, blocked422 { error, blockers }the promote dialog lists what to make Shared first
FileValidationError400 { error, files }the write client parses the offending files

Validating a request

Validate with validate(target, schema) from src/validate.ts, never with sValidator directly — its default failure body adds success and echoes the submitted body back as data.

app.post("/", requireAuth, validate("json", boardCreateSchema), async (c) => {
  const data = c.req.valid("json");

Choosing the verb

PATCH applies a partial update: only the fields sent change. PUT replaces the resource whole. A resource has one address and one write verb per operation — never both PUT and PATCH for the same update.

Checking a response

A route whose response has an exported response schema sends it through respond(c, schema, value) from src/respond.ts instead of c.json. Under test it parses the value against the schema, so a dropped field fails the route's test rather than the frontend; production sends the value untouched.

The error seam

Seven cross-cutting failures are thrown, not returned. A single onError seam maps each to its status and emits the same { error } body, so a domain rule states its message once instead of once per caller:

ThrowBecomes
NotFoundError404
ValidationError400
LockedError403
ConflictError409
UnsupportedError501
UpstreamError502
RateLimitError429

A Postgres unique violation also maps to 409 — detect it through the shared helper rather than re-reading the driver's error shape. So does a foreign-key violation, as a backstop only: a delete guarded by a restrict reference should throw a ConflictError naming what still uses the row first.

if (!row) throw new NotFoundError("Card not found");
throw new ValidationError("Invalid user assignee");

A resource referenced in the request body that isn't in this Organization, or isn't Shared, is a NotFoundError (404) naming what couldn't be used — not a 422, and no extra detail fields beside error.

Throwing is what lets one rule serve more than one surface: the Kanban rules answer both the HTTP routes and the Agent tool set from a single place. Reach for the seam whenever the failure is one of those six; a 4xx that only one route can produce still answers inline with c.json({ error }, status). Both are current and roughly equally common — the seam is not a migration you should finish.

Test assertions

Assert against the key the response actually uses:

expect(body.error).toBe("Invalid user assignee");
expect(await res.json()).toEqual({ message: "Board deleted" });

A service test covering a thrown failure asserts the error, not a body:

await expect(fn()).rejects.toThrow(NotFoundError);

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.