baudcast
A socket-based, realtime messaging API; designed for the internet of things.
baudcast is a node module that allows machine-to-machine (M2M) communication of internet-connected devices over a simple and configurable REST API.
No registration/setup required, just start baudcasting and receiving key-value data right away.
Installation
Open your app's folder in the terminal and run the following command:
$ npm install baudcast
Usage
baudcast can be easily configured to use custom endpoints and response templates.
As an example, the HAPI-REST API specification has been implemented with baudcast:
var app = ;var bodyParser = ;var server = ;var client = ;var baudcast = server client; app; // necessary for handling POST variables app; /* set up endpoint to make a baudcast */app;app; // GET works too /* set up endpoint to get last baudcast */app; /* set up endpoint to get last 800 baudcasts */app; /* set up custom response template */var template = verb: get: 'getting' create: 'creating' { var response = this: "succeeded" by: thisverbaction the: resourceType with: data ; return response; } { var response = this: "failed" with: apiErrorCode || 500 because: why ; return response; }; baudcast; app;server;console;
baudcasting
Simply call the following URL(as set up in the code) to make a new baudcast:
http://{some-host}:3000/baudcast/for/{thing}?foo=bar&baz=qux
The server will respond with:
The POST method can also be used to baudcast valid JSON data.
Getting baudcasts
The last 800 baudcasts made by a thing over the last 24 hours can be retrieved by calling the following URL:
http://{some-host}:3000/get/baudcasts/from/{thing}
The server will return an array of baudcasts in the following form:
The latest baudcast made by a thing can be retrieved by making a call to the following URL:
http://{some-host}:3000/get/last/baudcast/from/{thing}
The server will return a single baudcast in the following form:
Apart from the API endpoints, a device can also subscribe to a thing (or publish a new baudcast) using the popular socket.io framework.
To use baudcast with js, just include the socket.io script:
and use the following code:
var socket = ; socket; // you can subscribe to as many things you like socket; socket;
Each baudcast received, for a subscribed thing will be an Object of the form:
{
thing: "{thing}",
created: 1402642240997,
content: {
foo: "bar",
baz: "qux"
}
}
API
for(thing, content)
This function makes a new baudcast for a thing.
from(thing, callback)
This function executes callback(baudcast) everytime a thing makes a new baudcast.
route.makeNewBaudcast(req, res)
This is the app handler for making a new baudcast. This supports POST as well as GET variables.
route.getLastBaudcast(req, res)
This is the handler for retrieving the most recent baudcast made by a thing. Since baudcasts are realtime and ephemeral, they are only stored for 24 hours.
route.getBaudcasts(req, res)
This is the handler for retrieving all the baudcasts made by a thing. Again, because baudcasts are ephemeral, only the last 800 baudcasts are stored.
useTemplate(newTemplate)
This function is used to specify the response template of the REST API. Note that it's argument is a JSON object that should contain the methods respondSuccess
and respondFailure
, whose signatures should follow guidelines in the example.