* @ngdoc service * @kind function * @name $http * @requires ng.$httpBackend * @requires $cacheFactory * @requires $rootScope * @requires $q * @requires $injector * * @description * The `$http` service is a core Angular service that facilitates commun
(requestConfig)
| 11681 | </example> |
| 11682 | */ |
| 11683 | function $http(requestConfig) { |
| 11684 | |
| 11685 | if (!isObject(requestConfig)) { |
| 11686 | throw minErr('$http')('badreq', 'Http request configuration must be an object. Received: {0}', requestConfig); |
| 11687 | } |
| 11688 | |
| 11689 | if (!isString(requestConfig.url)) { |
| 11690 | throw minErr('$http')('badreq', 'Http request configuration url must be a string. Received: {0}', requestConfig.url); |
| 11691 | } |
| 11692 | |
| 11693 | var config = extend({ |
| 11694 | method: 'get', |
| 11695 | transformRequest: defaults.transformRequest, |
| 11696 | transformResponse: defaults.transformResponse, |
| 11697 | paramSerializer: defaults.paramSerializer |
| 11698 | }, requestConfig); |
| 11699 | |
| 11700 | config.headers = mergeHeaders(requestConfig); |
| 11701 | config.method = uppercase(config.method); |
| 11702 | config.paramSerializer = isString(config.paramSerializer) ? |
| 11703 | $injector.get(config.paramSerializer) : config.paramSerializer; |
| 11704 | |
| 11705 | var requestInterceptors = []; |
| 11706 | var responseInterceptors = []; |
| 11707 | var promise = $q.when(config); |
| 11708 | |
| 11709 | // apply interceptors |
| 11710 | forEach(reversedInterceptors, function(interceptor) { |
| 11711 | if (interceptor.request || interceptor.requestError) { |
| 11712 | requestInterceptors.unshift(interceptor.request, interceptor.requestError); |
| 11713 | } |
| 11714 | if (interceptor.response || interceptor.responseError) { |
| 11715 | responseInterceptors.push(interceptor.response, interceptor.responseError); |
| 11716 | } |
| 11717 | }); |
| 11718 | |
| 11719 | promise = chainInterceptors(promise, requestInterceptors); |
| 11720 | promise = promise.then(serverRequest); |
| 11721 | promise = chainInterceptors(promise, responseInterceptors); |
| 11722 | |
| 11723 | if (useLegacyPromise) { |
| 11724 | promise.success = function(fn) { |
| 11725 | assertArgFn(fn, 'fn'); |
| 11726 | |
| 11727 | promise.then(function(response) { |
| 11728 | fn(response.data, response.status, response.headers, config); |
| 11729 | }); |
| 11730 | return promise; |
| 11731 | }; |
| 11732 | |
| 11733 | promise.error = function(fn) { |
| 11734 | assertArgFn(fn, 'fn'); |
| 11735 | |
| 11736 | promise.then(null, function(response) { |
| 11737 | fn(response.data, response.status, response.headers, config); |
| 11738 | }); |
| 11739 | return promise; |
| 11740 | }; |
no test coverage detected