MobiCycle Ltd
MobiCycle Ltd

Reputation: 329

NodeRED & IBM Watson: How do I insert Watson's response {{payload}} into my index.html?

I have uploaded an index.html and css folder to project.mybluemix.net

In NodeRED, Watson's output prints as {{payload}} to a /results page.

I want my results to print to the existing index.html page without overriding the file.

How would I merge the two?

Cheers,

Upvotes: 1

Views: 307

Answers (1)

chughts
chughts

Reputation: 4737

You are missing the call to the Watson service, but other than that, yes that is all that you need to do. The first time you open your application page the browser will issue a HTTP GET. You application should respond to that get with a web page. You use a template to build the web page.

 <HTTP Input - GET>  --> <Template>   -->  <HTTP Output>

If you are calling a Watson service, say Natural Language Classifier, then you need a piece of text that you want to classify, and a classifier that you want to use to classify the text. You will also need some credentials to be able to use the Watson service.

So your web page should provide a mechanism for the text to be either entered or determined. That would come in either as a POST or a GET - its your choice. Your application determines the text, calls the Watson service, then passes the response from the service to a template which returns a response webpage.

 <HTTP Input - GET or POST>  --> <Function> --> <Watson Service> --> <Template>   -->  <HTTP Output>

If you know how to write templates then you could consider combining the templates into one template, and make the HTTP Input the same. You would need application logic, in the form of a function or a switch or a change to help determine whether you have enough information to call the Watson Service, and what the template should display.

Before you try this, get comfortable with templates and writing application logic in node-RED.

Upvotes: 1

Related Questions