What is the advantage of using Restangular over ngResource?

ngResource does not return promises in the latest stable release (currently 1.0.6). Additionally, it looks like Restangular exposes more verbs than ngResource (it exposes PUT, OPTIONS, PATCH, etc).

If you don't need the additional verbs and are on the unstable branch of AngularJS (which includes promises for ngResource), I don't see any major reason to use Restangular over ngResource.

Use whatever you feel comfortable with.


I'm the creator of Restangular.

I've created a section on the README with the differences against $resource. You can check them out here https://github.com/mgonto/restangular/blob/master/README.md#differences-with-resource

Anyway, as a sum up, besides the additional features and the promise based approach, the idea is that Restangular can also handle all of your URLs, so that you don't have to know anything about them.

Suppose that you have something like this for cars : /users/123/cars/456

In $resource, You'd have to construct that URL manually and you'd also have to construct the $resource object for this manually. Restangular helps you in this by "remembering" the URLs.

So if you do in some place

Restangular.one("users", 123).get().then(function(user) {
  $scope.user = user;
});

// Some other code

//Automatically does the request to /users/123/cars as it remembers in which object you're asking it.
$scope.user.getList('cars')

Hope this helps!


As a following up to the above answers and for new readers, like me, interested in those thoughts :

"And if that happens Restangular seems like it will disappear and become irrelivant."

"What happens in three months when this guy drops support for Restangular because Google's ngResource caught up to all the features it was missing."

  • [ asked 2 years ago ]

In my opinion the only guarantee to the survive of an open-source library is the community built around it. a best example would be mariaDB and WebScaleSQL which both of them were born as a growing fork to the great relational database management system MySQL.

At this writing time Restangular having 6699 stars and 727 forks is now moving forward to Restangular 2.0 which is meant to support angularJs 2.0 and ES6.

  • discussion about : https://github.com/mgonto/restangular/issues/890.
  • first repo preview : https://github.com/mgonto/restangular/tree/2.0-wip
  • ng-europe conference presented by mgonto : https://youtu.be/fWar75R1NGo

I found Restangular's RequestInterceptor quite handy to remove some fields from the object before making the Request. Most REST webservices i am currently working with don't expect the id in the object data in a PUT request for example, just in the url. Generally they don't expect extra data fields that can not be updated by PUT (like the id, or a slug which is generated by setting the title etc). I found this to be straightforward with Restangular while i haven't figured out how to do it with $resource in a clean way, but i am sure its possible somehow.

Obviously one could also change the webservice to just ignore those extra fields, but thats not always possible.