Skip to content

Instantly share code, notes, and snippets.

@sap1ens
Created February 1, 2013 16:35
Show Gist options
  • Save sap1ens/4692429 to your computer and use it in GitHub Desktop.
Save sap1ens/4692429 to your computer and use it in GitHub Desktop.
Adding Backbone.js custom REST method
var MyModel = Backbone.Model.extend({
someMethod: function(opts) {
var url = this.url() + '/someMethod',
// note that these are just $.ajax() options
options = {
url: url,
type: 'POST'
};
// add any additional options, e.g. a "success" callback or data
_.extend(options, opts);
return (this.sync || Backbone.sync).call(this, null, this, options);
}
});
@alejandro-martinez
Copy link

perfect, thanks!

@felipecrv
Copy link

You can call this.sync directly http://backbonejs.org/docs/backbone.html#section-62

@mattduggan
Copy link

options = _.extend(options, opts);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment