Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Book Collection Example

This is an example, written in javascript (node.js), of a RES service with collections and resource references to books, which can be created, edited and deleted.

  • It exposes a collection, bookService.books, containing book model references.
  • It exposes book models,<BOOK_ID>, of each book.
  • It allows setting the books' title and author property through the set method.
  • It allows creating new books that are added to the collection with the new method.
  • It allows deleting existing books from the collection with the delete method.
  • It verifies that a title and author is always set.
  • It resets the collection and models on server restart.


Running the example

Run the following commands:

npm install
npm start

Open the client


Things to try out

Realtime updates
Run the client in two separate tabs to observe realtime updates.

System reset
Run the client and make some changes. Restart the node.js server to observe resetting of resources in clients.

Run the client on two separate devices. Disconnect one device, then make changes with the other. Reconnect the first device to observe resynchronization.

Web resources

Get book collection

GET http://localhost:8080/api/bookService/books

Get book

GET http://localhost:8080/api/bookService/book/<BOOK_ID>

Update book properties

POST http://localhost:8080/api/bookService/book/<BOOK_ID>/set


{ "title": "Animal Farming" }

Add new book

POST http://localhost:8080/api/bookService/books/add


{ "title": "Dracula", "author": "Bram Stoker" }

Delete book

POST http://localhost:8080/api/bookService/books/delete


{ "id": <BOOK_ID> }
You can’t perform that action at this time.