Skip to content

Commit

Permalink
add patchJson shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
calibr committed May 9, 2015
1 parent 64e80d9 commit d7f5fcf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -100,6 +100,10 @@ Send json `data` via POST method.

Send json `data` via PUT method.

### patchJson(url, data, options)

Send json `data` via PATCH method.

### Parsers

You can give any of these to the parsers option to specify how the response data is deserialized.
Expand Down
5 changes: 5 additions & 0 deletions lib/restler.js
Expand Up @@ -363,6 +363,10 @@ function putJson(url, data, options) {
return json(url, data, options, 'PUT');
}

function patchJson(url, data, options) {
return json(url, data, options, 'PATCH');
}

var parsers = {
auto: function(data, callback) {
var contentType = this.headers['content-type'];
Expand Down Expand Up @@ -526,6 +530,7 @@ mixin(exports, {
json: json,
postJson: postJson,
putJson: putJson,
patchJson: patchJson,
parsers: parsers,
file: multipart.file,
data: multipart.data
Expand Down
8 changes: 8 additions & 0 deletions test/restler.js
Expand Up @@ -523,6 +523,14 @@ module.exports['Deserialization'] = {
});
},

'Should patch and parse JSON via shortcut method': function(test) {
var obj = { secret : 'very secret string' };
rest.patchJson(host + '/push-json', obj).on('complete', function(data) {
test.equal(obj.secret, data.secret, 'returned: ' + util.inspect(data));
test.done();
});
},

'Should understand custom mime-type': function(test) {
rest.parsers.auto.matchers['application/vnd.github+json'] = function(data, callback) {
rest.parsers.json.call(this, data, function(err, data) {
Expand Down

0 comments on commit d7f5fcf

Please sign in to comment.