--- /dev/null
+(function () {
+ 'use strict';
+
+ var prefix = 'http://localhost:8080/';
+
+ angular
+ .module('app.rest')
+ .constant('API', {
+ CARS: prefix + 'api/cars',
+ CAR: prefix + 'api/cars/:carId'
+ });
+
+})();
* Rest service.
*/
/* @ngInject */
- function cars($http, $log) {
+ function cars($http, $log, API) {
return {
getAll: getAll
};
* Get cars from API REST.
*/
function getAll() {
- return $http.get('/api/cars')
+ return $http.get(API.CARS)
.then(getAllCompleted)
.catch(getAllFailed);
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();
<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 -->