Skip to content

Lesson 1 of 9 · 24m

Resource Modeling: Nouns Before Endpoints

How to choose resources, model relationships, and avoid RPC-shaped URLs that become impossible to extend.

The worst API designs start as a list of screens: /getInvoicePdf, /resendInvoiceEmail, /closeInvoice. They feel fast on day one and fossilize by month six, because every new use case needs another verb. A durable API starts from the opposite direction: identify the things clients manipulate, then let HTTP supply the verbs.

A resource is a thing with identity and state

/invoices/inv_9Zk2
/invoices/inv_9Zk2/pdf
/customers/cus_41Hm
/payments/pay_18Qp

A resource is not necessarily a database row. It is a stable conceptual object with a lifecycle and a representation. /invoices/inv_9Zk2/pdf can be a derived artifact; /invoices/inv_9Zk2/payment-attempts can expose data assembled from several tables. Clients do not care how you store it. They care whether the address means the same thing next year.

Model relationships as navigation, not embedding everything

GET /invoices/inv_9Zk2
{
  "id": "inv_9Zk2",
  "number": "INV-2026-0417",
  "status": "open",
  "customer": "cus_41Hm",
  "links": {
    "customer": "/customers/cus_41Hm",
    "payments": "/invoices/inv_9Zk2/payments"
  }
}

Embedding the customer object saves one request until a client needs customer fields in three places and receives three inconsistent snapshots. Return identifiers and links by default; offer expansion deliberately through an expand parameter only when the relationship is read-heavy and bounded.

Sometimes the right resource is the operation itself

POSTing close to /invoices/inv_9Zk2/actions/close is usually a design failure. POSTing to /invoice-closures is different: now the operation has an ID, a status, an audit trail, and can retry safely.

POST /invoice-closures
Idempotency-Key: 6d7d9067-4f8f-4b0f-a938-665c9f1ea63f

{"invoice": "inv_9Zk2", "reason": "paid_offline"}

The rule of thumb: if the operation can fail asynchronously, need auditing, or be retried, model it as a resource. If it is just setting one attribute, use PATCH on the parent.

Normalize use cases, not tables

Resist exposing CRUD for every table because the ORM made it easy. Start with real client jobs: list overdue invoices, capture payment, email receipt, refund charge. Each job maps to a small set of resource transitions. When a job does not fit, prefer adding a small subresource or operation resource over growing boolean query parameters into a parallel command language.

Field notes

  • Plural collection names plus opaque IDs age better than singular nouns plus numeric database IDs.
  • Never let a URL expose ownership semantics that depend on today's org chart; /accounts/acct_1/projects survives reorganizations better than /teams/17/projects when teams can merge.
  • If clients keep scraping one field out of a huge representation, that field probably deserves its own subresource.
  • Your public resource model is a promise. Internal refactors are cheap; renaming /tenants to /organizations after launch is not.

Was this lesson helpful?

Sign in to rate