agentleFS
AndreiBanu1AndreiBanu1/playwright-suite-skills/skills/write-api-client/SKILL.md

write-api-client

Skill1 starsChanged 3 months agoMITView on GitHub

Use when a request spec needs a call that no existing client method covers — adding a domain client, adding a method to one, or extending the shared transport helper. Covers where the endpoint path belongs, what the method should return, and when a new client is warranted at all. Reads conventions from .claude/test-profile.md.

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 8 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    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. Distinctive:

    Add the reusable call a spec is missing, at the right level.

    line 8
  2. Distinctive:

    Never reach for the shared transport to solve a domain problem.

    line 33
  3. Distinctive:

    No test logic: No branching on scenario, no conditional payload assembly for a particular test.

    line 67
  4. Very specific:

    Types over any: If the repo is typed, type the payload and the response.

    line 70
  5. Distinctive:

    Run lint and typecheck if the profile lists them.

    line 85
  6. Distinctive:

    No hardcoded hosts, tokens, tenant identifiers, or account numbers.

    line 89
  7. Distinctive:

    Do not log full responses from a client.

    line 91
  8. Distinctive:

    Do not add a method with no caller.

    line 93
  9. Distinctive:

    Do not duplicate an existing method under a new name because the old one returns an inconvenient shape.

    line 94

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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

Skill: write-api-client

Add the reusable call a spec is missing, at the right level.

Preconditions

  1. .claude/test-profile.md exists. If the profile records no client layer, calls in this repo are made directly from specs — adding a layer is an architectural change, so ask first rather than introducing one for a single spec.
  2. You know the endpoint, its method, its inputs, and the shape it returns.

Procedure

1. Decide the level before writing anything

Three levels, and picking the wrong one is the mistake this skill exists to prevent:

LevelChoose it when
Existing client methodThe endpoint's domain already has a client. Add a method. This is the common case.
New domain clientThe domain has no client and you can name at least two endpoints it will own.
Shared transportThe need is genuinely cross-cutting: a verb wrapper, a response envelope, a retry policy. Rare.

One endpoint does not justify a new client. Put the method on the nearest existing client and split later when a second endpoint arrives — a client with one method is indirection with no payoff, and premature domain boundaries are harder to undo than a later split.

Never reach for the shared transport to solve a domain problem. Anything domain-specific there is paid for by every caller in the suite.

2. Read the neighbouring client

Record the export style, the constructor dependencies, where paths are held, what methods return (raw driver response, unwrapped body, typed envelope), how headers and auth are threaded, and whether errors throw or come back as data. Match all of it — a client that returns a different shape from its siblings makes every spec that uses it read differently.

3. Write it

class <Domain>Client {
  // endpoint paths as named constants or functions — never inline strings in methods
  // constructor takes only its transport dependency

  // one method per operation, named for the operation, not the verb
}

Paths as named constants. Inline path strings scattered through methods are the reason a version bump becomes a twelve-file change.

Base URL, tenant and credentials are injected, not embedded. The client knows the path shape; the environment supplies the rest. A client with a hostname in it works in exactly one environment and looks like it works everywhere.

Return the whole response, not just the body, unless the neighbours do otherwise. Specs need to assert on status, and a client that swallows it forces callers to guess.

Do not assert inside a client. A client that throws on a non-2xx cannot be used to test error paths — and error paths are where the interesting bugs are. Return the failure; let the spec judge it.

No test logic. No branching on scenario, no conditional payload assembly for a particular test. Parameters in, request out.

Types over any. If the repo is typed, type the payload and the response. An untyped client is a client whose contract lives only in the specs that happen to call it.

4. GraphQL specifics

Wrap the existing query/mutate transport rather than assembling documents by hand. Keep documents where the repo keeps them — colocated files or exported constants — and pass variables as variables. Interpolating a value into a document string breaks on quotes and nulls, and defeats server-side query caching.

5. Wire and verify

Register the client wherever the profile says clients reach specs (register-fixture), then prove it with one real call from a spec. A client verified only by reading is not verified.

Run lint and typecheck if the profile lists them.

Guardrails

  • No hardcoded hosts, tokens, tenant identifiers, or account numbers. This is the file where such values most often get committed, because it feels like infrastructure rather than a test.
  • Do not log full responses from a client. Auth-adjacent endpoints return tokens, and CI logs are usually far more widely readable than the repo.
  • Do not add a method with no caller.
  • Do not duplicate an existing method under a new name because the old one returns an inconvenient shape. Fix the shape, or take the inconvenience.

Done when

The method exists at the justified level, paths are constants, no environment values are embedded, one spec calls it green, and you have reported the path plus what you added and why at that level.

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.