document-an-api-endpoint-with-a-runnable-example
Use when writing reference docs for an HTTP API endpoint. Specifies method, path, parameters, a copy-pasteable request, a real response, and each error with its fix.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 81
- Forks
- 17
01 前言 Front Matter
- name
- document-an-api-endpoint-with-a-runnable-example
- description
- Use when writing reference docs for an HTTP API endpoint. Specifies method, path, parameters, a copy-pasteable request, a real response, and each error with its fix.
02 资源文件 3
- 许可证LICENSE1.0 KB
- 参考文档SOURCE.md374 B
- 参考文档TRUST.auto.yaml2.2 KB
03 SKILL.md 正文
Document an API Endpoint with a Runnable Example
API docs are read by someone writing a client under deadline. Give them a request they can paste into curl and the exact response, then the errors.
Procedure
- Open with the method and path in a code span:
POST /v1/invoices. State the purpose in one sentence. - Give an auth line: required scopes and header, e.g.
Authorization: Bearer $ACME_TOKEN, scopeinvoices:write. - List path, query, and body parameters in a table with name, type, required, and default. Mark enum values exhaustively: status in {draft, open, paid, void}.
- Provide a runnable curl example with real-looking values and the token in a variable so the reader substitutes one thing:
curl -sS -X POST https://api.acme.dev/v1/invoices -H "Authorization: Bearer $ACME_TOKEN" -d '{"amount_cents":500,"currency":"usd"}' - Show the actual JSON response with a 200, including field types. Do not hand-wave with an empty object.
- Document every error the endpoint can return: code, HTTP status, meaning, and the fix. For 409 conflict_idempotency, tell the caller to reuse the same Idempotency-Key or fetch the existing resource.
- Note rate limits and the
Retry-Afterheader value the endpoint sends. - State idempotency behaviour explicitly: which key header, and the retention window (e.g. 24h).
- Add one worked error example showing the fix applied.
- Document pagination if the endpoint lists: the cursor field, the page size limit, and the parameter to advance.
- Keep the request and response in a consistent order so a reader scans top-to-bottom.
- Give a timestamp and timezone convention for any date field (
ISO 8601, UTC).
Pitfalls
- A request example that omits the auth header, so the first copy-paste returns 401.
- Showing only the happy path response; callers then mishandle the 4xx cases.
- Parameter tables that mark everything optional when the server rejects missing fields.
- Field descriptions that restate the name, such as "amount: the amount".
- Documenting the success status only, hiding that the same verb returns 202 when queued.
- A pagination note that omits the maximum page size, so callers guess and get truncated results.
- Amounts shown as floats where the field is integer minor units, causing rounding bugs downstream.
Verification
curl -sS -o /dev/null -w '%{http_code}\n' -X POST "$BASE/v1/invoices" -H "Authorization: Bearer $ACME_TOKEN" -d '{}'
# run against staging; the code must match the documented error for that input
Run every documented example against staging and confirm status codes and response shapes match the docs exactly.
04 同仓库更多 Skills
recipe-performance
Diagnose a specific MetaMask user flow's real-app performance and Sentry critical-user-flow telemetry with deterministic mm-harness recipes. Use for CUF boundaries, cold/warm/background-resume behavior, latency regressions, lifecycle tags, duplicate or blocking network requests, long tasks, layout/paint cost, screen redraws, React rerenders, or browser trace analysis where tests alone cannot prove the real app.
mexc-spot-websocket
MEXC Spot WebSocket workflows for public streams, protobuf handling, depth maintenance, listen keys, and private streams without exposing API keys.
mexc-spot-rest
MEXC Spot REST workflows for public data, signed account requests, orders, wallet/admin actions, and secure signing without exposing API keys.
mexc-futures-websocket
MEXC Futures WebSocket workflows for public streams, private account/order/position streams, ping/pong, subscriptions, and depth maintenance.
0xklen-version-and-refresh-sanctions-lists
暂无简介
verify-tests-cover-changed-lines
Use when a PR adds code that the existing suite may not exercise. Measures patch coverage — the share of newly changed lines hit by tests — before approving.