katamari-client
js client for katamari though the service should be usable with the standard websocket and http/fetch request method, this client provides encode/decode methods and a reconnecting websocket abstraction.
Messages will arrive either as a snapshot or a patch the subscription keeps a cache of the latest state.
how to
install
npm i katamari-client
object
import Katamari from 'katamari-client'
const client = Katamari('localhost:8800/box')
let msgs = []
client.onopen = async () => {
await client.publish('box', { name: 'something 🧰' }) // create
await client.publish('box', { name: 'still something 💾' }) // update
await client.unpublish('box') // delete
}
client.onmessage = async (msg) => { // read
msgs.push(msg)
if (msgs.length === 4) {
client.close()
console.log(msgs)
}
}
client.onerror = (err) => {
client.close()
}
list
import Katamari from 'katamari-client'
const client = Katamari('localhost:8800/box/*')
let msgs = []
client.onopen = async () => {
const id = await client.publish('box/*', { name: 'something 🧰' }) // create
await client.publish('box/' + id, { name: 'still something 💾' }) // update
await client.publish('box/custom', { name: 'custom something 🧰' }) // create
await client.unpublish('box/*') // delete list
}
client.onmessage = async (msg) => { // read
msgs.push(msg)
if (msgs.length === 5) {
client.close()
console.log(msgs)
}
}
client.onerror = (err) => {
client.close()
}