This is a React version of Resgate's Book Collection example. It contains both a client and a server written for node.js.
The purpose of this example is to show how ResClient can be used together with React. To learn more about writing services for Resgate, visit the Resgate project.
- Have NATS Server and Resgate running
- Have node.js installed
Run the following commands:
npm install
npm start
Or run server and client in two separate consoles:
npm run start-server
npm run start-client
Open the client
http://localhost:3000
In the example, ResClient resources are passed as props to the React components. This allows the component to listen to events itself without having to rely on the parent, but uses forceUpdate
to trigger rendering on events.
Suggestions on how to improve the example are appreciated.
Realtime updates
Run the client in two separate tabs to observe realtime updates.
System reset
Run the client and make some changes. Restart the server to observe resetting of resources in client.
Resynchronization
Run the client on two separate devices. Disconnect one device, then make changes with the other. Reconnect the first device to observe resynchronization.
GET http://localhost:8080/api/bookService/books
GET http://localhost:8080/api/bookService/book/<BOOK_ID>
POST http://localhost:8080/api/bookService/book/<BOOK_ID>/set
Body
{ "title": "Animal Farming" }
POST http://localhost:8080/api/bookService/books/add
Body
{ "title": "Dracula", "author": "Bram Stoker" }
POST http://localhost:8080/api/bookService/books/delete
Body
{ "id": <BOOK_ID> }