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 bareborrowaction would not. - Hide storage details. If the database splits a book across
books,editionsandshelf_locationstables, the API may still expose onebookresource. Callers should not break because you reorganised your tables.