title: AngularJS service with data from REST API
body: <p>I'm starting to read about <code>services</code> in Angular and confused as to how to use them with <code>$http</code>.</p>
  
  <p>I currently use <code>$http</code> to fetch data from my REST API like the code below;</p>
  
  <pre><code>$scope.getRestaurant = function () {
      var baseUrl = 'http://api.example.com/web/restaurant/details/' + $scope.id;
      $http({
          method: 'get',
          url: baseUrl,
          headers: {'Content-Type': 'application/json'}
      }).
      success (function(data, status, headers, config){
          if(data &amp;&amp; !angular.isUndefined(data) ){
              $scope.restaurant = data;
          } else {
              $scope.restaurant = [];
          }
      }).
      error(function(data, status, headers, config) {
          //$scope.messageFailure(data.message);
      });
  }
  </code></pre>
  
  <p><code>$scope.id</code> is a value on my <code>controller</code> how can I turn this function into <code>service</code> and then access the data returned in my controller?</p>