Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Designing RESTful APIs  ›  Lesson

Resource Modeling

Resource modeling 14 minResource modeling means choosing the nouns callers need to fetch or change on their own, turning important actions into resources, and hiding how the data is stored.

Resource Modeling

Before writing a single endpoint, BookNook has to decide what its API is about. Is a loan its own thing, or a field on a book? Is a reservation a resource, or an action? These choices shape every URL, every response and every future change, and they are much cheaper to get right on paper than in production.

The rule

Model the nouns your callers care about, not the tables you store.

A resource is anything a caller wants to name, fetch or change. Resource modeling means choosing those nouns, their fields and how they relate.

Start from what callers do, then find the nouns in those sentences:

  • "A member borrows a book" → nouns: member, book, and the borrowing itself, a loan.
  • "A member reserves a book that is out" → a reservation.
  • "A librarian sees overdue loans" → not a new noun; a filter on loans.

Resources come in two shapes:

  • A collection holds many: /v1/books.
  • An item is one member of it: /v1/books/42.

Relationships can be shown by nesting (/v1/members/7/loans) or by reference, a field holding the other resource's id:

{
  "id": 901,
  "book_id": 42,
  "member_id": 7,
  "borrowed_on": "2026-09-25",
  "due": "2026-10-09",
  "returned_on": null
}

Two habits keep models healthy:

  • Turn important actions into resources. "Borrow" becomes creating a loan: POST /v1/loans. The loan then has its own id, history and status, which a bare borrow action would not.
  • Hide storage details. If the database splits a book across books, editions and shelf_locations tables, the API may still expose one book resource. Callers should not break because you reorganised your tables.

The shortcut

Write three caller stories, underline the nouns, then ask of each: does a caller need to fetch or change this on its own? Yes → resource. No → a field or a filter.

Modeling "a member returns a late book and pays a fine"Step 1 of 4
  1. Underline the nouns

    member, book, loan, fine.

The trap is copying the database schema into URLs, like /v1/book_shelf_location_rows. That leaks internals and freezes them.

Drills

Answer fast — trust the rule.

quick drill

Which is the best resource for "a member borrows a book"?

quick drill

"Show me overdue loans." What should "overdue" become?

quick drill

BookNook stores books in three tables. What should the API expose?

quick drill

Which pair is a collection and one of its items?

Remember

  • Model the nouns your callers care about, not the tables you store.
  • Shortcut: underline the nouns; fetched or changed on its own → resource, otherwise a field or filter.
  • Trap: leaking the database schema into the API.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainModel reservations

Members can reserve a book that is on loan and are notified when it comes back. Decide whether a reservation is a resource, a field or a filter, and sketch its URLs and fields.