This module is in npm as askwatson
. It provides a simple API for asking Watson a question on Bluemix using the
question_and_answer service
.
Basically you will need to get set up on Bluemix/CF and follow the instructions given
for the sample Node.js application here https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/qaapi/#commonApplication, including running the cf
commands, but
I have factored out that code a bit into two modules, so your application can
be cleaner. In case you need help finding the cf
command line program you can download it from here https://github.com/cloudfoundry/cli/releases (under Installers) and install it with dpkg -i <filename>
.
The first module is called bluemix-request-simple
and it has the parts for pulling
the host and port out of the environment and using them in a request.
The other module is this one, which is very simple to use:
watson;
This will need to run on Bluemix so a more complete example would be:
var watson = restify = ; var server = restify; server; server;
Note that if you use GET as in this example it will be simpler to test but you can only use short questions (try curl "http://whatever.mybluemix.net/healthcare/What+is+the+most+common+kind+of+cancer"
). If you use something longer for the question it will blow up the app, so you will probably want to use POST.