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);
};
Written by Phil Freo
Related protips
1 Response
Thanks for sharing!
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Patch
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#