03-book-collection

command
v0.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2021 License: MIT Imports: 5 Imported by: 0

README

Book Collection Example

Tags: Models, Collections, Linked resources, Call methods, Resource parameters

Description

A simple library management system, listing books by title and author. Books can be edited, added, or deleted by multiple users simultaneously.

Prerequisite

  • Download and install Go
  • Install NATS Server and Resgate (done with 3 docker commands).

Install and run

git clone https://github.com/jirenius/go-res
cd go-res/examples/03-book-collection
go run .

Open the client

http://localhost:8083

Things to try out

Realtime updates
  • Open the client in two separate tabs.
  • Add/Edit/Delete entries to observe realtime updates.
System reset
  • Open the client and make some changes.
  • Restart the service to observe resetting of resources in all clients.
Resynchronization
  • Open the client on two separate devices.
  • Disconnect one device.
  • Make changes using the other device.
  • Reconnect the first device to observe resynchronization.

API

Request Resource Description
get library.books Collection of book model references.
call library.books.new Creates a new book.
get library.book.<BOOK_ID> Models representing books.
call library.book.<BOOK_ID>.set Sets the books' title and author properties.
call library.book.<BOOK_ID>.delete Deletes a book.

REST API

Resources can be retrieved using ordinary HTTP GET requests, and methods can be called using HTTP POST requests.

Get book collection
GET http://localhost:8080/api/library/books
Get book
GET http://localhost:8080/api/library/book/<BOOK_ID>
Update book properties
POST http://localhost:8080/api/library/book/<BOOK_ID>/set

Body

{ "title": "Animal Farming" }
Add new book
POST http://localhost:8080/api/library/books/new

Body

{ "title": "Dracula", "author": "Bram Stoker" }
Delete book
POST http://localhost:8080/api/library/books/delete

Body

{ "id": <BOOK_ID> }

Documentation

Overview

This is an example RES service that shows a lists of books, where book titles can be added, edited and deleted by multiple users simultaneously.

* It exposes a collection, `library.books`, containing book model references. * It exposes book models, `library.book.<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. * It serves a web client at http://localhost:8083

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL