DEV Community

Gabe Garcia
Gabe Garcia

Posted on

API documentation examples and how to rewrite unclear endpoint docs

Most API docs are written by the people who built the API. That's why they're accurate and still hard to use. The author already knows what a "resource" is, which field is required and why the call returns 409. The reader doesn't.

This post walks through API documentation examples for the parts first time users read most. Endpoint summaries, parameter tables, request and response samples, error docs and auth steps. Each section shows a terse version and a clearer rewrite.

What a reader needs from an endpoint page

A developer landing on an endpoint page wants to answer five questions fast.

  1. What does this call do?
  2. What do I have to send?
  3. What will I get back?
  4. What can go wrong?
  5. Can I copy something that works?

If your page answers those in that order, you're ahead of most docs.

Endpoint summaries

Terse.

POST /v1/invoices. Creates invoice object.

Clearer.

POST /v1/invoices creates a draft invoice for a customer. The invoice isn't sent until you call the send endpoint, so you can add line items first.

The rewrite says what happens and what doesn't. That second sentence prevents a support ticket.

Terse.

DELETE /v1/webhooks/{id}. Deletes webhook.

Clearer.

DELETE /v1/webhooks/{id} stops sending events to that URL right away. Events already queued are dropped. This can't be undone, but you can create a new webhook with the same URL.

Parameter tables

A parameter table should say the type, whether it's required, the default and one plain sentence on what it changes.

Terse.

Name Type Description
due int Due date
cur string Currency

Clearer.

Name Type Required Description
due_date integer No Unix timestamp for when payment is due. Defaults to 30 days after creation.
currency string Yes Three letter ISO code in lowercase, such as usd or eur. Must match the customer's default currency.

Renaming the fields in the API is a bigger job, but you can always fix the description column today.

Request and response samples

Give a full example someone can paste into a terminal. Include headers, a realistic body and the response they'll see.

curl https://api.example.com/v1/invoices \
  -H "Authorization: Bearer sk_test_123" \
  -H "Content-Type: application/json" \
  -d '{
    "customer_id": "cus_8842",
    "currency": "usd",
    "due_date": 1767225600
  }'
Enter fullscreen mode Exit fullscreen mode
{
  "id": "inv_2051",
  "status": "draft",
  "customer_id": "cus_8842",
  "currency": "usd",
  "amount_due": 0,
  "due_date": 1767225600
}
Enter fullscreen mode Exit fullscreen mode

Then add one line explaining anything surprising. Here that's that amount_due stays at zero until you add line items. People will assume it's a bug otherwise.

Error documentation

Error docs are where terse writing hurts the most, because the reader is already stuck.

Terse.

409 Conflict. Resource state conflict.

Clearer.

409 Conflict means the invoice has already been sent, so it can't be edited. To change it, void the invoice and create a new one. The response body includes current_status so you can check before retrying.

A good pattern for every error is three parts. What happened, why it usually happens and what to do next.

{
  "error": {
    "code": "invoice_not_editable",
    "message": "Invoice inv_2051 was sent and can no longer be edited.",
    "hint": "Void it with POST /v1/invoices/inv_2051/void and create a new draft."
  }
}
Enter fullscreen mode Exit fullscreen mode

If you control the API, put that hint in the response itself. The best error docs are the ones developers never have to open.

Authentication steps

Terse.

Auth via bearer token. See dashboard.

Clearer.

Every request needs an API key in the Authorization header. Create a key in the dashboard under Settings, then API keys. Test keys start with sk_test_ and never move real money. Live keys start with sk_live_ and should only live in server side code.

Spell out where the button is. "See dashboard" assumes the reader has already found it.

Quick checks before you publish

  • Read it as a newcomer. Load the docs in an incognito tab and attempt the first call with nothing else to lean on.
  • Define every noun once. If "workspace" and "account" mean different things, say so near the top.
  • Use the same names everywhere. If the field is customer_id, don't call it "client ID" in the prose.
  • Show the unhappy path. One example of a failed request teaches as much as three successful ones.
  • Date your changes. A short note on when behavior changed saves people from debugging old blog posts.

Rewriting long explanations

Endpoint summaries are short, but concept pages, like how pagination or rate limits work, often turn into walls of text. When you're rewriting those, it helps to see how others restructure dense prose. These paragraph rephraser examples show long paragraphs split into clearer sentences while the meaning holds.

For a concept page you've stared at too long, run one paragraph through Rephrase AI to get fresh wording to compare, and then check that every field name, status code and limit in the new version still matches your spec.

Docs aren't done when they're accurate. They're done when someone new can make their first call without asking you anything.

Top comments (0)