Tags: Models, Collections, Linked resources, Call methods, Resource parameters, Store
This is the Book Collection example where all changes are persisted using a badgerDB store.
git clone https://github.com/jirenius/go-res
cd go-res/examples/04-book-collection-store
go run .
Open the client
http://localhost:8084
Run the client and make changes to the list of books. Restart the service and observe that all changes are persisted.
The store sorts books by title. Change the title of one of the books. Observe how the list remains sorted by title.
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. |
Resources can be retrieved using ordinary HTTP GET requests, and methods can be called using HTTP POST requests.
GET http://localhost:8080/api/library/books
GET http://localhost:8080/api/library/book/<BOOK_ID>
POST http://localhost:8080/api/library/book/<BOOK_ID>/set
Body
{ "title": "Animal Farming" }
POST http://localhost:8080/api/library/books/new
Body
{ "title": "Dracula", "author": "Bram Stoker" }
POST http://localhost:8080/api/library/books/delete
Body
{ "id": <BOOK_ID> }