Generic datafetcher for GET, POST, PUT, DELETE and returns promises.
$ grunt test
This will make Grunt run the linting task and then execute the unit tests.
Include angular_datafetcher.js
in your index.html
<script type="text/javascript" src="path/to/angular_datafetcher.js"></script>
Then add the module as a dependencie in your app
var myAppModule = angular.module('MyApp', ['angular-datafetcher']);
and then you can inject $datafetcher
wherever you like:
angular.module('MyApp').controller('MainCtrl', function ($scope, $datafetcher) { ... });
The fetcher returns a promise so use the then
callback to retrieve the data.
$datafetcher.get('http://someapi.com/api/apimethod').then(function (data) {
console.log(data);
}, function (reason) {
console.log(reason);
});
- url - the complete URL of the requested resource
- cacheIt - should the result be cached?
- url - the complete URL of the requested POST location
- payload - the payload that should be sent with the POST method
- url - the complete URL of the requested PUT location
- payload - the payload that should be sent with the PUT method