Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add HTTP PATCH support

  • Loading branch information...
commit af8a79557e3052aa3acf69a90d214320e99ba5c4 1 parent 03db492
@Hebo Hebo authored
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
17 lib/superagent.js
@@ -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
4 test/server.js
@@ -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
7 test/test.request.js
@@ -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');
Please sign in to comment.
Something went wrong with that request. Please try again.