Skip to content

Instantly share code, notes, and snippets.

@tankcdr
Created February 7, 2015 21:38
Show Gist options
  • Save tankcdr/82e841a77514708bae75 to your computer and use it in GitHub Desktop.
Save tankcdr/82e841a77514708bae75 to your computer and use it in GitHub Desktop.
watson-developer-cloud and restify question answer service example
'use strict'
var wdc = require('watson-developer-cloud-alpha'),
restify = require('restify'),
server = restify.createServer(),
question_and_answer_travel = wdc.question_and_answer({
username: '[user name]',
password: '[password]',
version: 'v1',
dataset: 'travel'
})
server.use(restify.fullResponse())
.use(restify.bodyParser())
server.post('/travel/ask', function(req,res,next) {
var options = {
text: req.params.question
}
question_and_answer_travel.ask(options, function (err, response) {
if (err)
res.send(500,err)
else
res.send(200,response)
return res.next();
})
})
server.listen(8080,function() {
console.log('Travel service listening on '+server.url)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment