dj_ueg
Last Updated: February 25, 2016
·
4.402K
· philfreo
Philsq100

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);
};
Say Thanks
Respond

1 Response
Add your response

21471
None

Thanks for sharing!

over 1 year ago ·