Example watch

Subscribe for watching a node or things in ThingsDB. A successful run request will respond with a OK (17) package.


[scope, ...IDs]

The IDs are the thing-IDs you want to watch.

The socket needs to be authorized before sending a watch request. See the auth example for how to authorize a socket connection.


As an example we assume that we want to watch a thing with Id 3 for mutations. Instead of a single ID, we could add as much IDs as we wanted.

ThingsDB will throw a WARNING event to you socket connection in case some given Id does not exist within the given collection scope. Other IDs will be watched and the response to you watch request will still be OK (17).

This is the data we want to pack:

["//stuff", 3]

Serializing the above using MessagePack results in the following 10 bytes:


Now we create the header. For this example we just use Id 0:

  • Data length (13) \x0a\x00\x00\x00
  • Identifier (0) \x00\x00
  • Run package type (35) \x23
  • Inverse type check bit (218) \xdc

Sending the Query package


Responding OK package


A few seconds (or less) later, you will receive an init or warning event on the socket connection.

See the watching documentation for more information.