showcase: AngularJS REST service, API CARS
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Tue, 25 Aug 2015 19:19:28 +0000 (21:19 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Tue, 25 Aug 2015 19:19:57 +0000 (21:19 +0200)
angularjs/showcase/src/showcase/app/rest/rest.constants.js [new file with mode: 0644]
angularjs/showcase/src/showcase/app/rest/rest.service.js
angularjs/showcase/src/showcase/app/rest/rest.service.spec.js
angularjs/showcase/src/showcase/index.html

diff --git a/angularjs/showcase/src/showcase/app/rest/rest.constants.js b/angularjs/showcase/src/showcase/app/rest/rest.constants.js
new file mode 100644 (file)
index 0000000..a82540f
--- /dev/null
@@ -0,0 +1,13 @@
+(function () {
+  'use strict';
+
+  var prefix = 'http://localhost:8080/';
+
+  angular
+    .module('app.rest')
+    .constant('API', {
+      CARS: prefix + 'api/cars',
+      CAR: prefix + 'api/cars/:carId'
+    });
+
+})();
index e2eef11..618eb82 100644 (file)
@@ -22,7 +22,7 @@
    * Rest service.
    */
   /* @ngInject */
-  function cars($http, $log) {
+  function cars($http, $log, API) {
     return {
       getAll: getAll
     };
@@ -36,7 +36,7 @@
      * Get cars from API REST.
      */
     function getAll() {
-      return $http.get('/api/cars')
+      return $http.get(API.CARS)
         .then(getAllCompleted)
         .catch(getAllFailed);
 
index 8fa8d70..7449f84 100644 (file)
@@ -4,21 +4,23 @@ describe('app.rest', function() {
   var $httpBackend;
   var $log;
   var cars;
+  var API;
 
   beforeEach(function() {
     module('app.rest');
 
-    inject(function(_$httpBackend_, _$log_, _cars_) {
+    inject(function(_$httpBackend_, _$log_, _cars_, _API_) {
       $httpBackend = _$httpBackend_;
       $log = _$log_;
       cars = _cars_;
+      API = _API_;
     });
   });
 
   describe('cars service', function () {
 
     it('should invoke GET all cars', function () {
-      $httpBackend.expectGET('/api/cars').respond({});
+      $httpBackend.expectGET(API.CARS).respond({});
 
       cars.getAll();
 
index 2b3c913..4c19879 100644 (file)
@@ -58,6 +58,7 @@
     <script src="/src/showcase/app/rest/rest.service.js"></script>
     <script src="/src/showcase/app/rest/rest.route.js"></script>
     <script src="/src/showcase/app/rest/rest.controller.js"></script>
+    <script src="/src/showcase/app/rest/rest.constants.js"></script>
     <script src="/src/showcase/app/core/core.module.js"></script>
     <script src="/src/showcase/app/app.module.js"></script>
     <!-- endinject -->