O'Reilly logo

Backbone.js Cookbook by Vadim Mirgorod

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Synchronizing models and collections with a RESTful service

In this recipe, we are going to learn how to synchronize models and collections with a RESTful service. Just as we did in all other recipes, we will use MongoLab for a RESTful service.

How to do it...

Follow these steps to get familiar with REST in Backbone.js:

  1. Create a configuration object that stores a server URL and an authentication key for MongoLab.
    var appConfig = {
      baseURL: 'https://api.mongolab.com/api/1/databases/billing-app/collections/',
    
      addURL: '?apiKey=kNCrqJUqB4n1S_qW7wnXH43NH9XKjdIL'
    }
  2. Define a url() method that returns a resource URL to perform a REST request. Such URLs should contain a model ID, if a model is already synchronized with a RESTful service. Also, such URLs should ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required