AngularJS : Factory, Service and Provider with example

AngularJS Factory Example :

userApp.factory('userService', function($http) {
var self = this;
return {
getAllUsers : function() {
return $http.get('user/getAllUsers');
},
getUserById : function(id) {
return $http.get('user/getUserById/' + id);
},
addUser : function(userData) {

return $http.post('user/saveUser', userData);
},
deleteUser : function(id) {
return $http.get('user/deleteUser/' + id);
},
getUser : function(user) {
return $http.post('user/getUser', user);
}
}

});

AngularJS Service Example

userApp.service('myService', function () {
  this.name = '';
    this.setName = function (newName) {
     this.name = newName;
     return this.name;
   };
 });

AngularJS Provider Example
//defining provider

 app.provider('configurable', function () {
 var firstName = '';
 this.setName = function (firstName) {
      firstName= firstName;
 };
 this.$get = function () {
      return {
         name: firstName
       };
  };
 });
//configuring provider
 app.config(function (configurableProvider) {
 configurableProvider.setName("Saksham Chauhan");
 });