Hello all,

So I create a simple Rest API to help calls RestFull:

angular.module('voip.services').service('RestAPI', function ($http, $q) {
>
> var _restAPI = {};
>
> var _urlBase = '';
>
> var _deferred;
>
>
>> _restAPI.setUrl = function(urlBase) {
>
> _urlBase = urlBase;
>
> }
>
>
>> _restAPI.getUrl = function() {
>
> return _urlBase;
>
> }
>
>
>> _restAPI.findAll = function() {
>
> _deferred = $q.defer();
>
> $http.get(_urlBase).success(function(data){
>
> _deferred.resolve(JSON.parse(data["DATA"]));
>
> }).error(function(err, status){
>
> _deferred.reject(err["MSG_ERROR"]);
>
> });
>
> return _deferred.promise;
>
> }
>
>
>> _restAPI.create = function(grupo) {
>
> _deferred = $q.defer();
>
> $http.post(_urlBase, grupo).success(function(data) {
>
> _deferred.resolve(JSON.parse(data["DATA"]));
>
> }).error(function(err, status) {
>
> _deferred.reject(err["MSG_ERROR"]);
>
> });
>
> return _deferred.promise;
>
> }
>
>
>> _restAPI.update = function(id) {
>
> _deferred = $q.defer();
>
> $http.put(_urlBase + "/:id", id).then(function(response) {
>
> _deferred.resolve(JSON.parse(data["DATA"]));
>
> }, function(err){
>
> _deferred.reject(err["MSG_ERROR"]);
>
> });
>
> }
>
>
>> _restAPI.destroy = function(id) {
>
> _deferred = $q.defer();
>
> $http.delete(_urlBase + "/:id", id).then(function(response) {
>
> _deferred.resolve(JSON.parse(data["DATA"]));
>
> }, function(err){
>
> _deferred.reject(err["MSG_ERROR"]);
>
> });
>
> }
>
>
>> return _restAPI;
>
> });
>
>
I hope you like, is just for study but if help someone I'll be very happy. 

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to