Skip to content

Commit 9607c35

Browse files
committed
Merge pull request #209 from calibr/master
Add patchJson shortcut
2 parents 72d99df + d7f5fcf commit 9607c35

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ Send json `data` via POST method.
100100

101101
Send json `data` via PUT method.
102102

103+
### patchJson(url, data, options)
104+
105+
Send json `data` via PATCH method.
106+
103107
### Parsers
104108

105109
You can give any of these to the parsers option to specify how the response data is deserialized.

lib/restler.js

+5
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,10 @@ function putJson(url, data, options) {
364364
return json(url, data, options, 'PUT');
365365
}
366366

367+
function patchJson(url, data, options) {
368+
return json(url, data, options, 'PATCH');
369+
}
370+
367371
var parsers = {
368372
auto: function(data, callback) {
369373
var contentType = this.headers['content-type'];
@@ -527,6 +531,7 @@ mixin(exports, {
527531
json: json,
528532
postJson: postJson,
529533
putJson: putJson,
534+
patchJson: patchJson,
530535
parsers: parsers,
531536
file: multipart.file,
532537
data: multipart.data

test/restler.js

+8
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,14 @@ module.exports['Deserialization'] = {
534534
});
535535
},
536536

537+
'Should patch and parse JSON via shortcut method': function(test) {
538+
var obj = { secret : 'very secret string' };
539+
rest.patchJson(host + '/push-json', obj).on('complete', function(data) {
540+
test.equal(obj.secret, data.secret, 'returned: ' + util.inspect(data));
541+
test.done();
542+
});
543+
},
544+
537545
'Should understand custom mime-type': function(test) {
538546
rest.parsers.auto.matchers['application/vnd.github+json'] = function(data, callback) {
539547
rest.parsers.json.call(this, data, function(err, data) {

0 commit comments

Comments
 (0)