BlueMix Node-RED Calculator REST Service

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to my screencast my name is Adrienne Solis and today I'm going to create a calculator rest service using no dread on bluemix so let's get started to create the rest calculator service we'll use an HTTP request node an HTTP response node in the calculation will be performed in a function this function node is basically a JavaScript node I'm going to implement the URL add and rename this to HTTP request calculator ad now I'll wire these two together double click on the function node name the function node calculator ad well first here we'll begin by creating a couple of variables so I'll create an X variable a Y variable a total variable to hold the calculation value and now what I'll do is I'll extract and store the X parameter from the request parameter into the X variable this is a first request parameter I will do the same for Y extract the Y parameter from the request now I need to perform the calculation so I'll store the value in total I need to parse the X which is a string as an INT and parse the Y as an nth and perform the addition now I need to create a new variable to create the JSON string that I want to pass to the HTTP response node so let's create this and store the value into the response message and I'll basically format a JSON string of total : and then I use a the value total from the variable so I'm using these escape characters to include the double quotes another escape character closing curly brace so now I need to take this JavaScript script string which is representing the JSON string and store it into the message payload and the message payload will be returning to the message so again I have my X and y variables have my total variable response message that I've created extracting the x and y parameters storing them into X&Y performing the calculation using the parse int function creating my json string and storing it into the payload so now that I have this JavaScript object JSON string I actually want to convert it into a standard JSON string by using the JSON node so the output of the calculator ad function I'll wire it to the JSON node which will convert the JavaScript object to a JSON string and then I'll pass that JSON string to the HTTP response node I'll rename this to HTTP response ok so this looks good it's the HTTP request it's getting passed into the function performing the calculation converting it to a JSON string and responding back as a HTTP response let's deploy this successfully it's deployed now open up a new browser tab I'll put in the URL calc and pass in the x and y values let's see if this works there it is total equal 15 I'll change it 7 to a 10 total equals 18 so the calculation is working and there you have it it's a very simple flow to do a simple calculation thanks for watching
Info
Channel: Adrian Solis
Views: 10,891
Rating: 4.8904109 out of 5
Keywords: BlueMix, Node-RED, NodeRed, REST, Node.js, IBM, Calculator, Cloud, JSON, JavaScript
Id: xntpcrLoeyE
Channel Id: undefined
Length: 5min 57sec (357 seconds)
Published: Wed Jun 10 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.