Last Updated: February 25, 2016
·
5.894K
· 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 ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
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