From 270c67312a74cd19d80083e1394166d576e3afbb Mon Sep 17 00:00:00 2001 From: Ciro Nunes Date: Mon, 20 Jan 2014 11:21:31 -0200 Subject: [PATCH] fix($http): add the PATCH shortcut back The shortcut was dropped because it had a lot of unkowns about PATCH. Since we already know that using PATCH is good (http://www.mnot.net/blog/2012/09/05/patch), and only IE8 has issues with that, let's add the shortcut back. --- src/ng/http.js | 16 +++++++++++++++- test/ng/httpSpec.js | 9 +++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ng/http.js b/src/ng/http.js index f20d54fd60db..a24037bbd902 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -869,7 +869,21 @@ function $HttpProvider() { * @param {Object=} config Optional configuration object * @returns {HttpPromise} Future object */ - createShortMethodsWithData('post', 'put'); + + /** + * @ngdoc method + * @name ng.$http#patch + * @methodOf ng.$http + * + * @description + * Shortcut method to perform `PATCH` request. + * + * @param {string} url Relative or absolute URL specifying the destination of the request + * @param {*} data Request content + * @param {Object=} config Optional configuration object + * @returns {HttpPromise} Future object + */ + createShortMethodsWithData('post', 'put', 'patch'); /** * @ngdoc property diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index a0417d9ad99c..76ab59c8ebff 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -897,6 +897,15 @@ describe('$http', function() { $http.put('/url', 'some-data', {headers: {'Custom': 'Header'}}); }); + it('should have patch()', function(){ + $httpBackend.expect('PATCH', '/url', 'some-data').respond(''); + $http.patch('/url', 'some-data'); + }); + + it('patch() should allow config param', function() { + $httpBackend.expect('PATCH', '/url', 'some-data', checkHeader('Custom', 'Header')).respond(''); + $http.patch('/url', 'some-data', {headers: {'Custom': 'Header'}}); + }); it('should have jsonp()', function() { $httpBackend.expect('JSONP', '/url').respond('');