app.service('myService', function($http) {
// GET http://api.example.com/users
return $http.get('api://users');
});
app.service('myService', function($http, apiUrl) {
// GET http://api.example.com/users
return $http.get(apiUrl + '/users');
});
- Flexibility — interceptors for the win !
- Readability — no extras string concatenation or helper calls
- “Testability”
bower install angular-fancy-url --save
then
angular.module('myApplication', [
'fancyURL'
]).config(function($httpProvider, httpFancyURLProvider) {
$httpProvider.interceptors.push('httpFancyURL');
httpFancyURLProvider.use({
'api' : 'http://api.example.com/',
});
})