Skip to content

Instantly share code, notes, and snippets.

@tankcdr
Created February 9, 2015 13:45
Show Gist options
  • Save tankcdr/62ef95f09ae16ad3e3c6 to your computer and use it in GitHub Desktop.
Save tankcdr/62ef95f09ae16ad3e3c6 to your computer and use it in GitHub Desktop.
watson-developer-cloud and restify question answer service example that runs on Bluemix
use strict'
var wdc = require('watson-developer-cloud-alpha'),
restify = require('restify'),
server = restify.createServer(),
question_and_answer_travel = wdc.question_and_answer({
version: 'v1',
use_vcap_services: true,
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(process.env.VCAP_APP_PORT,function() {
console.log('Travel service listening on '+server.url)
})
cf create-service question_and_answer question_and_answer_free_plan cmmqa
curl -H "Content-Type: application/json" -X POST http://wdctravel.mybluemix.net/travel/ask \
-d '{"question": "Do I need a visa to enter Italy?"}'
applications:
- services:
-cmmqa
name: wdctravel
path: .
memory: 128M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment