CloudPlugs REST Library  1.0.0
for JavaScript
CloudPlugs JavaScript Client Library

CloudPlugs REST Client for JavaScript is a library to perform HTTP requests to CloudPlugs servers. The official repository is: https://github.com/cloudplugs/rest-js

The Cloudplugs IoT Platform

Cloudplugs is a cloud based IoT platform to enable the fast prototyping, connection, deployment and management of smart "Things" (sensors, smartphones, home appliances, etc.). Different objects can interact with each other by publishing and/or reading any type of data on shared channels through simple communication protocols. You can learn more at http://www.cloudplugs.com/how-it-works/ and you can sign-up on http://www.cloudplugs.com/register to start connecting your Things.

Library Guide

You can use this library to perform HTTP requests to the CloudPlugs platform either from a browser or as a Node.js module.

Installation

Download the library and copy the cp.rest.lib.js file in your project directory. To use the library from within a browser readable page include it in your page:

<script src="cp.rest.lib.js"></script>

If you are using the library as a Node.js module include it in your script:

var cloudplugs = require('./cp.rest.lib');

Usage

Create a new instance, setting the initialization parameters:

  • id String - the authentication identifier.
  • password String - the authentication password.
  • isMaster bool - to run the script as a master user
  • debug bool - optional, trace activity in the console and accept invalid https certificates. Default: false.
  • url String - optional, Set an URL that will be used as base for all web services. Default: https//api.cloudplugs.com/iot/ .
  • acceptUnauthorized bool - optional, in case of https, the certificate won't be verified. Default: false.
  • dontLoadCA bool - optional, prevent the library from loading the included CA certificates. Default: false.

Example:

AUTH_PLUGID = 'dev-xxxxxxxxxxxxxxxxxx';
AUTH_PASS = 'your-password';
AUTH_MASTER = true;
var client = new cloudplugs.RestClient({
id: AUTH_PLUGID,
password: AUTH_PASS,
isMaster: AUTH_MASTER
});

Now you are ready to to invoke methods and perform REST requests to the server!

Executing REST HTTP requests

When your instance of the library is ready, you can execute HTTP requests to the server by invoking any of the request methods. All the requests are asynchronous and are performed according to the Cloudplugs REST API documentation. Example:

client.publishData({
entries: [{ channel:'temperature', data:getTemp() }],
cb: function(err,id) {
console.log('Publication: '+(err ? 'failed' : 'successful'));
if (err) {
console.error(err);
}
}
});