Created
February 26, 2016 17:47
-
-
Save adamburvill/01e651d1dfa4da998fa4 to your computer and use it in GitHub Desktop.
Basic service exposing a $resource in angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
// @ngInject | |
function Book($resource){ | |
var resource = $resource('/api/books/:id', {id: '@id'}, { | |
update: {method: 'PUT'}, | |
subscribe: {method: 'GET', id: '@id', url: '/api/books/:id/subscribe'}, | |
}); | |
return { | |
query: function() { | |
return resource.query().$promise; | |
}, | |
get: function(id) { | |
return resource.get({id: id}).$promise; | |
}, | |
save: function(data) { | |
return resource.save(data).$promise; | |
}, | |
update: function(data) { | |
return resource.update(data).$promise; | |
}, | |
delete: function(id) { | |
return resource.delete({id: id}).$promise; | |
}, | |
subscribe: function(id) { | |
return resource.subscribe({id: id}).$promise | |
} | |
}; | |
} | |
angular | |
.module('app') | |
.service('Book', Book) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment