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
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#