Skip to content

Commit

Permalink
Merge pull request danwrong#71 from g-k/add-patch-method
Browse files Browse the repository at this point in the history
Add shortcut for PATCH requests
  • Loading branch information
ayoung committed Feb 22, 2012
2 parents b4030c6 + 4376de7 commit 42eacac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/restler.js
Expand Up @@ -274,6 +274,10 @@ function get(url, options) {
return request(url, shortcutOptions(options, 'GET')); return request(url, shortcutOptions(options, 'GET'));
} }


function patch(url, options) {
return request(url, shortcutOptions(options, 'PATCH'));
}

function post(url, options) { function post(url, options) {
return request(url, shortcutOptions(options, 'POST')); return request(url, shortcutOptions(options, 'POST'));
} }
Expand Down Expand Up @@ -418,6 +422,9 @@ mixin(Service.prototype, {
get: function(path, options) { get: function(path, options) {
return get(this._url(path), this._withDefaults(options)); return get(this._url(path), this._withDefaults(options));
}, },
patch: function(path, options) {
return patch(this._url(path), this._withDefaults(options));
},
put: function(path, options) { put: function(path, options) {
return put(this._url(path), this._withDefaults(options)); return put(this._url(path), this._withDefaults(options));
}, },
Expand Down Expand Up @@ -449,6 +456,7 @@ mixin(exports, {
request: request, request: request,
service: service, service: service,
get: get, get: get,
patch: patch,
post: post, post: post,
put: put, put: put,
del: del, del: del,
Expand Down
7 changes: 7 additions & 0 deletions test/restler.js
Expand Up @@ -82,6 +82,13 @@ module.exports['Basic'] = {
}); });
}, },


'Should PATCH': function(test) {
rest.patch(host).on('complete', function(data) {
test.re(data, /^PATCH/, 'should be PATCH');
test.done();
});
},

'Should PUT': function(test) { 'Should PUT': function(test) {
rest.put(host).on('complete', function(data) { rest.put(host).on('complete', function(data) {
test.re(data, /^PUT/, 'should be PUT'); test.re(data, /^PUT/, 'should be PUT');
Expand Down

0 comments on commit 42eacac

Please sign in to comment.