API Test Prompt — the Contract Is the Subject
Status codes, response shapes, 401 vs 403, idempotency — API tests that test the contract, not the implementation.
Overview
API tests that only check 200-and-some-JSON miss what APIs break: the 400 that comes back as a 500, the 401/403 confusion that leaks resource existence, the error body whose shape nobody asserted. This setup generates the API contract test suite: every response asserting status code, body shape, and meaningful headers; auth as behavior (missing credentials → 401, wrong permissions → 403 — different tests); error responses held to their contract as strictly as success; idempotency of repeated requests; and payload limits enforced at the documented boundary.
Workflow
-
Test the contract, not the code
Request in, response out — the suite holds the documented behavior, whatever the implementation does inside.
-
Separate the auth tests
401 for who-are-you, 403 for you-can't — one test each, never merged.
-
Repeat the dangerous requests
The idempotency scenario: send the completed request again and assert the documented behavior, not luck.
Why This Works
- Contract framing tests what consumers depend on instead of implementation details
- The 401/403 distinction encodes the auth correctness most suites blur
- Error-shape assertions protect the clients that parse failures programmatically
Best for
- Public and partner-facing endpoints
- APIs whose error contract is part of the product
- Teams that learned the 401-vs-403 lesson in production
Not for
- Writing the API documentation — that's the Markdown Output Builder
- Defining the response format itself — that's the JSON Output Prompt Builder
Use cases
- Testing REST endpoints before they go public
- Catching the invalid payload that 500s instead of 400s
- Asserting error response shapes that clients parse