Using a RESTful API in Backbone

In the previous chapter, we created a self-contained, in-browser web application using localStorage to persist data. Now we have a server set up to sync that data to disk instead, allowing our app to be used in any browser on potentially any machine. All we have to do is adapt our code.

We need all of the same external dependencies as in the previous chapter, so let’s start by installing the same Bower modules as before:

 $ ​​bower​​ ​​init
 $ ​​bower​​ ​​install​​ ​​--save​​ ​​jquery
 $ ​​bower​​ ​​install​​ ​​--save​​ ​​backbone

Now on to our Backbone models and collections. We no longer need the initial data or the Backbone.sync shim from the previous chapter. All we need to do to tell Backbone how to ...

Get CoffeeScript, 2nd Edition 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.