Creating a simple state CRUD REST Service using NodeRed on Bluemix

This is my first article and video in my BlueMix series. BlueMix is an amazing platform where you can get a highly scalable solution up and running very quickly. Because there is so much to BlueMix, I figure I would start off with something simple but useful. A state storage and retrieval service. A simple REST API based on JSON implemented as a NodeRed application on the IBM BlueMix platform. We will be doing the CRU of CRUD (create, read, update, delete), so no delete in this first stab.

The first flow is the “Store State” which is an HTML POST that takes this JSON object:

"_id": "eb7c844a07e4ad183df6e7921498c898",
"_rev": "8-47b75155b16372e040ec9803c550b91c",
"key": "BobBalfe","state": "0"

Don’t get intimidated by the complexity of that because you actually get most of that information from the get state flow below. But first lets look at the store state flow:
Screen Shot 2016-03-29 at 10.44.19 PM

Now we could just slam that information right into the database but I don’t like doing that without at least one or two checks prior. The switch statement takes care of that, I basically require a “key” property in the JSON in order to continue. Otherwise I take the entire load, with the unique key, and store it. If no key is specified the original load is sent back to the caller with an error:

Screen Shot 2016-03-29 at 10.45.10 PM

Now for the easy part, the “get state” REST call. This takes a very simple load:

     "key" : "some big unique key"

Yep, thats it. And if you have an entry in the database you will get an array with a record back, otherwise you will just get an empty array. This is because I am really not doing much in this flow. I pass the load into a function that constructs the search string, pass it on to the Cloudent search node and pass that functions results to the caller – pretty basic.

Screen Shot 2016-03-29 at 10.49.26 PM

Well now you can see me walk through how this flow was constructed with Larry commentating on the side.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

Up ↑

%d bloggers like this: