Asynchronous REST/Comet API



Asynchronous REST/Comet API

·         Overview

·         Prerequisites

Using the Comet API

Next Steps



Asynchronous REST/Comet API



The Everyware Device Cloud (EDC) platform provides support for Asynchronous REST/Comet APIs. This solution allows client applications to use HTTP and REST to subscribe on topics of interest and have matching data being streamed to them in real-time. Together with the ability of publishing data through the REST API described in the previous section, this completes the Everyware Device Cloud (EDC) offering of a full MQTT to HTTP bridge.


The following example illustrates how the EDC Comet API can be used to receive streaming data using REST APIs.



Complete the following steps before starting this example:

  1. Complete the edc-java-client example detailed in Connecting to the Cloud in Java to publish data to your Everyware Cloud account in real-time.




Using the Comet API

You should have already downloaded the edc-comet example available on the GitHub repository at https://github.com/eurotech/edc-examples/.


In your workspace under edc-comet/src/main/webapp, open the file index.html in your favorite text editor.  This file follows the data model used in the edc-java-client example and assumes that your data is published under the sample/data topic and contains metrics named int, dbl, flt.


Change the following lines of code to use your Everyware Cloud Username, Password, and Account and save your changes.



<td><input type="text" id="url" size="60" value="https://api-sandbox.everyware-cloud.com/v2/streams/subscribe.json"/></td>
<td><input type="text" id="username" size="60" value="myEdcUserName"/></td>
<td><input type="password" id="password" size="60" value="myEdcPassword"/></td>
<td><input type="text" id="topic" size="60" value="myEdcAccount/%2B/%23"/></td>



Using the Firefox or Safari browser, open index.html. (Note: this does not work with Internet Explorer.) Click on the Subscribe button shown in the following screen captue.



In Eclipse, run the edc-java-client application by selecting the green Run button  in the Launch toolbar to make a connection to the Cloud and start publishing data.  The data displays in real-time as shown in the following screen capture.



See the full JavaScript code for details on the API operation.




Next Steps

This is a very simple example to show the Comet/streaming capabilities of the EDC platform.  You are encouraged to package this example into a proper Web application before deploying it into production.