Making our application interactive
We've improved our application to be fed data from a database. Now it's time for the payoff—we can let users interact with our application, and their actions can be reflected in our data. We're going to add a feature where customers may buy a pet they like, directly through the website! We've got some implementation work to do.
To send a request to buy a pet, we'll need the pet ID that's used as the database key. This is returned when we query all the records, but so far we've been dropping it from the results we send to the browser. We'll update the data in routes/pets.coffee
:
exports.list = (req, res) -> nStore.new 'data/pets.db', (err, petsDB) -> return _fail err, res if err? petsDB.all (err, result) -> return _fail err, res if err? response = for key, pet of result pet.id = key pet res.send response
We've added id
as a property to each of the JSON objects we send out. Now our client-side code can use...