Adding an endpoint for data

Now that we've got a dynamic server backing our app, one thing we can do to improve our application is handle the data a bit better. Right now, we simply throw the list of pets in with the rest of the code, where it's hard to get at and hard to modify.

First, let's move our list of pets to a separate file. It's easier to maintain the data when it isn't mixed with application logic, and this will provide a nice separation of concerns for later. We'll create a new directory named data and a new file named data/pets.coffee. This file will contain our entire list of pets that used to be in assets/js/animal.coffee:

module.exports = [ name: "Kelsey" type: "dog" age: 2 breed: "Labrador" description: "A sweet and loyal dog. Loves ...

Get CoffeeScript Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.