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:
"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:
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:
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.
Well now you can see me walk through how this flow was constructed with Larry commentating on the side.