Small helper library to ease the use of Putki, a tiny topic-based messaging server. If you need to use this library inside Node.js, you can install the eventsource library and pass it in the options.
- Install the package using your favourite Node.js package manager:
# npm
npm install putki.js
-
If you do not already have a client registered, register a client in the Putki dashboard.
-
Create a new instance of Putki and give it the client secret and an API url, and then you are ready to go!
const putki = new Putki({
apiUrl: 'http://your-putki-api.com',
clientSecret: 'your-client-secret'
});
// Subscribe to events from 'some-topic'.
const unsub = await putki.subscribe('some-topic', (evt) => {
console.log('got event', evt);
});
// unsubscribe from 'some-topic' after 10 seconds
setTimeout(() => unsub(), 10 * 1000);