Club a number of methods performing AJAX operations as one service in Angular JS

I am writing an application in which I have to write a number of functions performing AJAX operations. I want to put all these functions under one service in a module and invoke these functions in the controllers whenever they are required. I know that it can be done using Angular JS modules, but not getting right approach to resolve it.

Can anyone help me with this? It would be great if you can demonstrate with an example.

I actually did a short blog entry on this a while ago.

Basic example:

var app = angular.module('myApp', []);

//create a service:
app.factory('myService', function($http) {
   return {
      getFoo: function(success) {
        $http.get('/Foo/Url/Here').success(success);
      }
   }
});

//use it in a controller
app.controller('MyCtrl', function($scope, myService) {
    myService.getFoo(function(data) {
        $scope.foo = data;
    });
});

Example of using $http with $q for slicker results.

var app = angular.module('myApp', []);

//create a service:
app.factory('myService', function($http, $q) {
   return {
      getFoo: function() {
          var deferred = $q.defer();
          $http.get('/Foo/Url/Here').success(function(data) {
              deferred.resolve(data);
          }).error(function(){
              deferred.reject();
          });
          return deferred.promise;
      }
   }
});

//use it in a controller
app.controller('MyCtrl', function($scope, myService) {
    $scope.foo = myService.getFoo();
});