Adding REST-based Web Services to IoT Devices -

Adding REST-based Web Services to IoT Devices


In the first article in this two-part series on the Internet of Things (IoT) with Node.js and Intel Galileo Gen 2, I explained how to prepare the board to work with Intel XDK IoT Edition; and I reviewed basic use of the MRAA library.

In this article, I explain how to use Node.js to add REST interfaces and real-time notifications that enable an IoT board to communicate with other applications.

Providing a REST API .

In the previous article, I provided an example of a few lines of JavaScript code that could measure a rechargeable battery voltage by using the MRAA library. However, IoT projects require “things” to communicate with other “things” or applications. The huge number of modules available in Node.js makes it easier to generate interfaces. For example, the HTTP module allows you to create an HTTP server to generate a REST API to interact with the Intel Galileo Gen 2 board.

The following lines show a new version of main.js that uses the HTTP module to create an HTTP server that listens on port 1337 and provides a response for the GET method with a specific URL. (For all this work, I will continue using Intel XDK IoT Edition as the IDE. I described its use in the previous article. )

To read more of this external content, go to “Using JavaScript and Node.js to quickly add new capabilities to IoT projects.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.