Backbone.sync

This is responsible to handle connections between a RESTful server and the Backbone application is the Backbone.sync module. It transforms the fetch() and save() operations into HTTP requests:

  • fetch() is mapped as a read operation. This will make GET to the the urlRoot attribute with the model ID for a model or the url attribute for a collection.
  • save() is mapped as a create or update operation; it depends on the isNew() method:
    • This will be mapped as create if the model does not have an ID (isNew() method return true). A POST request is executed.
    • This will be mapped as update if the model already has an ID (isNew() method returns false). A PUT request is executed.
  • destroy() is mapped as a delete operation. This will make DELETE to the ...

Get Mastering Backbone.js 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.