Field notes, refined over time

Documentation

Concise guides that explain the concepts behind an API, reviewed and updated over the years, with examples you can read in a minute and apply right away.

Getting Started

An API is a contract between two programs: one asks for something in a defined format, and the other answers in a predictable way. Before calling any API, identify four things — the base URL, the available endpoints, the authentication method, and the data format.

Tip: Keep the base URL in a configuration value rather than hard-coding it. Switching from a sandbox to production then becomes a one-line change.

A minimal request has a method and a URL. Here is what a typical call looks like from the command line:

# Fetch a list of terms
curl https://api.apiwords.com/v1/terms?limit=10 \
  -H "Authorization: Bearer <your-api-key>"

HTTP Basics

Most web APIs speak HTTP. A request carries a method, a path, headers, and optionally a body. A response carries a status code, headers, and optionally a body.

The method describes the intent:

  • GET reads a resource without changing it.
  • POST creates a resource or triggers an action.
  • PUT replaces a whole resource; PATCH updates part of one.
  • DELETE removes a resource.

Headers such as Content-Type and Accept tell each side how the body is encoded and which format is preferred — usually application/json.

Request Design

A well-designed endpoint reads like a sentence. Use nouns for resources, keep verbs in the HTTP method, and put filters in the query string.

# Preferred
GET /v1/orders?status=open&sort=-created_at
# Avoid
GET /v1/getOpenOrdersSortedByDate

Version the path (/v1, /v2) so you can evolve the API without breaking existing clients. Return consistent shapes for both success and failure — predictability is more valuable than cleverness.

Authentication

Protected APIs need to know who is calling. The most common patterns are:

  • API keys — a static secret sent in a header; simple but must be protected.
  • Bearer tokens — short-lived credentials sent as Authorization: Bearer <token>.
  • OAuth 2.0 — a framework where a client obtains a limited-scope access token to act on a user's behalf.
Security: Never place a secret in client-side code, a public repository, or a URL query string. Read it from an environment variable on the server.

Reading a Spec

An OpenAPI document is the machine-readable description of an API. It lists paths, methods, parameters, request bodies, responses, and schemas. Start with the paths section to see what you can call, then check components/schemas to understand the data shapes.

paths:
  /v1/terms:
    get:
      summary: List glossary terms
      parameters:
        - name: limit
          in: query
          schema: { type: integer }

Treat the spec as the source of truth. If the implementation and the spec disagree, the spec is usually what client developers code against.

Errors & Status

Status codes group outcomes into families: 2xx success, 3xx redirect, 4xx client error, and 5xx server error. A helpful API adds a stable machine-readable code and a human-readable message to every error body.

{
  "error": {
    "code": "RATE_LIMITED",
    "message": "Too many requests. Retry after 30 seconds."
  }
}

For the full list of common codes, browse the glossary, where each status is explained in plain English.

Prefer definitions over guides?

The glossary covers fifty-plus terms in a single searchable list, organized so you can skim or study.

Open the Glossary