Skip to content

Conversation

@seattlevine
Copy link

While it is arguable more proper in REST to have modify do a PUT,
in tmsh, and therefore iControl REST, modify is a PATCH.

For example, do a tmsh modify sys global-settings: only what you set is
modified. But do a PUT to /mgmt/tm/sys/global-settings and items you don't
set (mgmtDhcp, for example) will be set.

While it is arguable more proper in REST to have modify do a PUT,
in tmsh, and therefore iControl REST, modify is a PATCH.

For example, do a tmsh modify sys global-settings: only what you set is
modified. But do a PUT to /mgmt/tm/sys/global-settings and items you don't
set (mgmtDhcp, for example) will be set.
@seattlevine seattlevine mentioned this pull request Jul 6, 2016
@thwi
Copy link
Owner

thwi commented Jul 8, 2016

Seems like a good enhancement in that it would bring .modify() more in line with tmsh behavior and thus be more intuitive.

Are you aware of any use cases for using PUT? I'm wondering if it would be worthwhile to introduce a different verb that uses PUT (maybe 'replace' or 'set'?) or perhaps provide an option to override the HTTP method for 'modify' if there's a compelling reason to do so.

Alternatively, PATCH could use a different verb like 'update' or 'append', but this doesn't seem as optimal since it diverges from tmsh.

@seattlevine
Copy link
Author

There likely are use cases for PUT, though I haven't tried it with this library. There are certainly cases where you don't necessarily get what you want when dealing with tmsh transactions (and therefore iControl REST transactions) due to mark and sweep. In these cases, doing a DELETE on an object with array items which are not in a sub-collection (rules of an AFM policy, for example) and a subsequent POST of that item with the same or modified rules fails but works if you use PUT instead of POST. Not sure what happens if you use PATCH here.

I tried to come up with a different verb to use for PATCH instead of modifying the existing behavior, but then realized that modify in tmsh really is PATCH. So, a different verb for PUT makes sense. 'replace' is decent since that maps to 'replace-all-with' nicely.

@gedeon007
Copy link

Could you @thwi please merge the commit from @seattlevine?

If you don't want to break the original code, what if you add a modify2 function where we have PATCH instead of PUT?

// Modify
iControl.prototype.modify = function(path, body, cb) {
var opts = { path: path, body: body, method: 'PUT' };
this._request(opts, cb);
};

// Modify2
iControl.prototype.modify2 = function(path, body, cb) {
var opts = { path: path, body: body, method: 'PATCH' };
this._request(opts, cb);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants