Last Updated: February 25, 2016
·
5.381K
· philfreo

Make Backbone.js use PUT for PATCH requests

When dealing with an API that supports partial PUT for updates (but not PATCH), you can make model.save({ foo: 1 }, { patch: true }); use PUT instead of PATCH by doing this:

// Override Backbone.sync to use the PUT HTTP method for PATCH requests
// when doing Model#save({...}, { patch: true });
var originalSync = Backbone.sync;
Backbone.sync = function(method, model, options) {
    if (method === 'patch') options.type = 'PUT';
    return originalSync(method, model, options);
};

1 Response
Add your response

Thanks for sharing!

over 1 year ago ·