I had an epiphany yesterday: Backbone's fetch and save methods are ridiculously simple. I've used backbone with a backend before, and the data persistence aspect was always this nebulous grey area in my mental model.
So how simple is it?
- Set the
urlproperty of your model to a REST endpoint that returns a json object.
- Call the model's
And that's it. The default
Backbone.sync method uses jQuery's ajax module under the hood to make ajax calls to the endpoint you've specified, and updates your model's data accordingly. It will even perform any client-side validation you've set up through that model's
As a bonus, backbone is setup to allow you to overwrite/extend the
Backbone.sync method if you need to perform server-side validation, authorization, error-handling, or other fancy things like web-sockets.