— HaeramKim, BuildYourOwnIoTPlatform — 1 min read
NOTE: this notes are from “Build Your Own IoT Platform” by Anand Tamboli. And I can’t speak english very well, so some sentences or word might be inappropriate and might have some misunderstandings.
topic-like, payload-like, count.

HTTP in node: Set method as GET and URL as /records/topic-like/:topic/payload-like/:payload/last/:count.function node:1// Create query2
3// if no authentication filter defined or available4// set the default value as 15if(!msg.req.authFilter)6 msg.req.authFilter = 1;7
8// wildcard used for API query is * and this needs to be converted into SQL wildcard character %9msg.topic = "SELECT id,topic,payload,timestamp" +10 " FROM thingsData WHERE" +11 " topic LIKE '" + msg.req.params.topic.12 replace(/\*/g, "%") + "'" +13 " AND" +14 " payload LIKE '" + msg.req.params.payload.15 replace(/\*/g, "%") + "'" +16 " AND deleted=0" +17 " AND (" + msg.req.authFilter + ")" +18 " ORDER BY ID DESC" +19 " LIMIT " + msg.req.params.count + ";";20
21return msg;authFilter to 1. It means we’re gonna allow all un-authorized user for now." AND (" + msg.req.authFilter + ")" + part: If authFilter is 1, this means true, so this query will works normally, but if it’s 0, this means false, so this query will fetch nothing.
deleted column to 1.PATCH HTTP method instead of GET method.
DELETE HTTP method to do it.
/timestamp, method to GET.function node to:1msg.payload = {2 timestamp: (new Date()).getTime().toString()3};4return msg;/randomcode/:len, method to GET.:len represents length of the random code.function node to:1var randomString = function(length) {2 var text = "";3 var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";4 for(var i = 0; i < length; i++) {5 text += possible.charAt(Math.floor(Math.random() * possible.length));6 }7 return text;8}9
10msg.payload = {11 code: randomString(msg.req.params.len)12};13
14return msg;node-red-contrib-uuid plugin to generate UUID./uuid, method to GET.function node to:1// Prepare response2msg.payload = {3 uuid: msg.payload4};5
6return msg;