Permalink
Browse files

add HTTP PATCH support

  • Loading branch information...
1 parent 03db492 commit af8a79557e3052aa3acf69a90d214320e99ba5c4 @Hebo Hebo committed Mar 7, 2012
Showing with 28 additions and 0 deletions.
  1. +17 −0 lib/superagent.js
  2. +4 −0 test/server.js
  3. +7 −0 test/test.request.js
View
@@ -685,6 +685,23 @@ var superagent = function(exports){
};
/**
+ * PATCH `url` with optional `data` and callback `fn(res)`.
+ *
+ * @param {String} url
+ * @param {Mixed} data
+ * @param {Function} fn
+ * @return {Request}
+ * @api public
+ */
+
+ request.patch = function(url, data, fn){
+ var req = request('PATCH', url);
+ if (data) req.send(data);
+ if (fn) req.end(fn);
+ return req;
+ };
+
+ /**
* POST `url` with optional `data` and callback `fn(res)`.
*
* @param {String} url
View
@@ -37,6 +37,10 @@ app.put('/user/:id', function(req, res){
res.send('updated');
});
+app.patch('/user/:id', function(req, res){
+ res.send('updated');
+});
+
app.get('/querystring', function(req, res){
res.send(req.query);
});
View
@@ -112,6 +112,13 @@ test('get()', function(next){
});
});
+test('patch()', function(next){
+ request.patch('/user/12').end(function(res){
+ assert('updated' == res.text, 'response text');
+ next();
+ });
+});
+
test('put()', function(next){
request.put('/user/12').end(function(res){
assert('updated' == res.text, 'response text');

0 comments on commit af8a795

Please sign in to comment.