how to make Generic method for rest call in angularjs -
how make generic method rest call in angularjs ?
i have tried single request, it's working fine
uiapproute.controller('test', ['$scope', 'checkstatus', function($scope, checkstatus) { $scope.data = {}; checkstatus.query(function(response) { $scope.data.resp = response; }); }]) uiappresource.factory('checkstatus', function($resource){ return $resource(baseurl + 'status', {}, {'query': {method: 'get', isarray: false}}) })
i want make generic request
please share sample,.. in advance
i'm using :
.factory('factoryresource', ['$resource', 'conf', function($resource, conf) { return { get: function(endpoint, method) { var resource = $resource(conf.baseurl + endpoint, {}, { get: { method: method || 'get' } }); return resource.get().$promise; } }; } ])
called :
factoryresource.get(conf.testendpoint, "post"); // make post , return promise , data object factoryresource.get(conf.testendpoint, "get"); // make getand return promise , data object factoryresource.get(conf.testendpoint); // make getand return promise , data object
with config file having :
angular.module('app.constant', []) .constant('conf', { baseurl: 'http://localhost:8787', testendpoint: '/api/test' });
Comments
Post a Comment