Source: services/request.js

/**
 * @ngdoc factory Requests
 * @name Requests
 * @description Handles all HTTP Requests
 * @requires $http
 * @memberof ClientApp
 */
app.factory('Requests', ['$http', '$rootScope', function(http, rootScope) {
  var Requests = {};
  Requests.data = [];
  Requests.post_data = []
  var base_url = "";
  var url = null;


  Requests.post = function post(resource, object, callBack) {
    var req = {
      method: 'POST',
      url: base_url + resource,
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + rootScope.token
      },
      data: object
    };


    if (object) {
      http(req)
        .success(function(data) {
          //this is the key
          callBack(data);
        })
        .error(function(data, response) {
          console.log(response + " " + data);
        });;
    }
  }


  Requests.get = function get(resource, callBack) {
    var data;
    var req = {
      method: 'GET',
      url: base_url + resource + "/user/" + rootScope.user._id,
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + rootScope.token
      }
    };

    http(req)
      .success(function(data) {
        //this is the key
        callBack(data);
      })
      .error(function(data, response) {
        console.log(response + " " + data);
      });;
  }
  return Requests;
}])