What is the right way to perform PATCH
request while saving model\'s attributes in Backbone.js?
You'll have to override Backbone.sync
and extend the existing method mapper
var methodMap = {
'create': 'POST',
'update': 'PUT',
'delete': 'DELETE',
'read': 'GET',
'patch': 'PATCH'
};
you'll have to create your own patch method on a model like
Backbone.Model.prototype.patch = function(options)
{
// some code here that checks what attributes have changed since last save
var xhr = (this.sync || Backbone.sync).call(this, 'patch', this, options);
return xhr;
}
I'm sure you can extend Backbone further to include OPTIONS
and HEAD
if you needed to
Note though, that even through jQuery supports the PATCH, OPTIONS and HEAD methods, your end-users' browser may not.