Serve resources

Write a service in the language of your choice:

const nats = require('nats')
nats.connect('nats://localhost:4222');

nats.subscribe('get.example.model', (req, reply) => {
	nats.publish(reply, JSON.stringify({ result: {
		model: { message: "Hello, World!" }
	}}));
});

Update the resource with an event:

nats.publish('event.example.model.change', JSON.stringify({
	values: { message: "Hello, Resgate!" }
}));

Get resources

Write a client that gets the resource and listens for updates:

let client = new ResClient('ws://localhost:8080');

client.get('example.model').then(model => {
	console.log(model.message); // Hello, World!
	model.on('change', () => {
		console.log("Updated!");
	});
});

Or access the resource using the REST API:

GET http://localhost:8080/api/example/model