diff --git a/app.js b/app.js index 8f0e06a..e93ecae 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,21 @@ var express = require('express'); // call express var app = express(); // define our app using express var bodyParser = require('body-parser'); +//var data = require('./responses.json'); + +// Declare variables +var fs = require('fs'), + obj + +// Read the file and send to the callback +fs.readFile('./responses.json', handleFile) + +// Write the callback function +function handleFile(err, data) { + if (err) throw err + obj = JSON.parse(data) + // You can now play with your datas +} app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); @@ -18,8 +33,8 @@ router.get('/', function(req, res) { res.json({ message: 'welcome to our ADAM AI api!' }); }); -router.get('/hi', function(req, res) { - res.json({ hi: 'Hello' }); +router.get('/:id', function(req, res) { + res.send(obj); }); app.use('/api', router); diff --git a/responses.json b/responses.json new file mode 100644 index 0000000..cbb6951 --- /dev/null +++ b/responses.json @@ -0,0 +1,6 @@ +{ + "hi": "Hello", + "How are you": "I am good, Thank you", + "Hello":"Hello", + "What is your name":"My name is ADAM AI" +}