Writing, reading, publishing and managing data is among the primary functionalities of Beebotte.
Beebotte API makes it easy for an object (physical or virtual channel) to publish data to Beebotte cloud platform. Beebotte associates data to resources; it is possible to publish one record at a time or to perform a bulk publish for resources on the same channel.
Beebotte provides server (backend) and client libraries for publishing data to resources. These libraries use either the REST API or the Websockets API.
Beebotte provides two types of resource data:Persistent
involving the Write API andTransient
involving the Publish API.
Remember that publishing in Beebotte is transient. Data will not be persisted to any database. You cannot read data that was previously published on Beebotte, you should rather use the write API for this case. Moreover, the resource you are publishing to does not require to exist in advance; publishing considers channels and resources as virtual notions.
When publishing data to a channel, the message access level is public by default
.
To publish a private message, the channel name must start with private-
prefix.
You can send a transient message as follows:
bclient.publish(
{channel: 'dev', resource: 'res1', data: 'Hello World'},
function(err, res) {
// Do something here
});
// Publish to private channel
bclient.publish(
{channel: 'private-dev', resource: 'res1', data: 'Hello World'},
function(err, res) {
// Do something here
});
## Create a Resource object
res1 = Resource(bclient, 'dev', 'res1')
## Publish to the resource
res1.publish('Hello World')
## Or simply
bclient.publish('dev', 'res1', 'Hello World')
## Publish to private channel
bclient.publish('private-dev', 'res1', 'Hello World')
// Create a Resource object
$res1 = new Resource($bclient, 'dev', 'res1');
// Publish to the resource
$res1->publish('Hello World');
// Or simply
$bclient->publish('dev', 'res1', 'Hello World');
// Publish to private channel
$bclient->publish('private-dev', 'res1', 'Hello World');
// Publish to public channel
bclient.Publish("dev", "res1", "Hello World");
// Publish to private channel
bclient.Publish("private-dev", "res1", "Hello World");
## cURL requires Channel Token authentication
curl -i -H "Content-Type: application/json" \
-H "X-Auth-Token: YOUR_CHANNEL_TOKEN" \
-X POST -d '{"data":"Hello World"}' \
http://api.beebotte.com/v1/data/publish/dev/res1
## Publish to private channel
curl -i -H "Content-Type: application/json" \
-H "X-Auth-Token: YOUR_CHANNEL_TOKEN" \
-X POST -d '{"data":"Hello World"}' \
http://api.beebotte.com/v1/data/publish/private-dev/res1
You can send an array of transient messages (bulk publish) as follows:
bclient.publishBulk({channel: 'dev', records: [
{resource: 'res1', data: 'Hello'},
{resource: 'res2', data: 'World'}
]}, function(err, res) {
// Do something here
});
bclient.publishBulk('dev', [
{resource: 'res1', data: 'Hello'},
{resource: 'res2', data: 'World'}
])
$bclient->publishBulk('dev', [
{resource: 'res1', data: 'Hello'},
{resource: 'res2', data: 'World'}
]);
// Create the message with bulk records to publish
List msgs = new List();
msgs.Add(new ResourceMessage("res1", "Hello"));
msgs.Add(new ResourceMessage("res2", "World"));
// Publsih the message (multiple records)
bclient.PublishBulk("dev", msgs);
## cURL requires Channel Token authentication
curl -i -H "Content-Type: application/json" \
-H "X-Auth-Token: YOUR_CHANNEL_TOKEN" \
-X POST -d '{"records":[{"resource":"res1","data":"Hello"},{"resource":"res2","data":"World"}]}' \
http://api.beebotte.com/v1/data/publish/dev
You can use the client side libraries to publish resources.
/* You are responsible for granting write access (publishing to a resource requires a write access) */
var bbt = new BBT('API_KEY', {auth_endpoint: 'authentication_URL'});
/* Subscrite to the resource with write access. Permissions are granted at the resource level
* Don't get confused with the permission names: read for reading, write for writing and publishing
*/
bbt.subscribe({channel: 'dev', resource: 'res1', write: true}, function(err, msg) {console.log(msg)} );
bbt.publish({channel: 'dev', resource: 'res1', data: 'Hello World'});
// If the message to publish is private, add 'private-' prefix to the channel name
bbt.subscribe({channel: 'private-dev', resource: 'res1', write: true}, function(err, msg) {console.log(msg)} );
bbt.publish({channel: 'private-dev', resource: 'res1', data: 'Hello World'});
Take into account the following points when using the client side publish API: