How to call API in angular js

app.factory("user_services", ['$http', function($http) {
var serviceBase = 'api/';
var obj = {};
obj.getCustomers = function(){
return $http.get(serviceBase + 'customers');
};
obj.getCustomer = function(customerID){
return $http.get(serviceBase + 'customer?id=' + customerID);
};
obj.insertCustomer = function (customer) {
return $http.post(serviceBase + 'insertCustomer', customer).then(function (results) {
return results;
});
};obj.updateCustomer = function (id,customer) {
return $http.post(serviceBase + 'updateCustomer', {id:id, customer:customer}).then(function (status) {
return status.data;
});
};

obj.deleteCustomer = function (id) {
return $http.delete(serviceBase + 'deleteCustomer?id=' + id).then(function (status) {
return status.data;
});
};

return obj;
}]);

Instead of using factories we also can use angular services to call the APIs.

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *