What is the advantage of using Restangular over ngResource?
Asked Answered
H

5

134

ngResource already seems really simple to implement things with...

What are the Advantages / Disadvantages of using Restangular over ngResource?

1.1.3 $resource will return promises and can be implimented using latest PR commit. Will future support be offered to $resource to support additional verbs that Restangular does? And if that happens Restangular seems like it will disappear and become irrelivant.

Hanahanae answered 14/5, 2013 at 23:48 Comment(3)
Why close? This is a valid question that should have definitive answers. Especially so early in the game when you are trying to decide what to use for your service calls. 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. Then if major $http release changes are made to angularjs --- you wont be able to upgrade because Restangualr's service calls will be expecting "something else" and you're going to end up gutting this framework you "decided to go with".Hanahanae
Check them out here github.com/mgonto/restangular/blob/master/…Laster
@DanKanze: Mid-level SO users are close-happy with questions like this. It's really frustrating since you're definitely not asking "which is better"... My only suggestion would be to carefully phrase questions in the future so as to not entice the "Subjective Gestapo" to descend upon you in their full might.Stanzel
L
231

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')
Laster answered 23/5, 2013 at 21:55 Comment(8)
+1 for jumping in on this. Who better to explain then the guy that built it himself haha!Hanahanae
Thanks :). Hope it's clear now. I've added the section to the README thanks to you and I received positive comments about it, as a lot of people didn't actually realize the main differences as they were spread across the BIIIG README file. If you have any doubt, you can post a question @Github :)Laster
how is .one('users', 123) any more or less "knowing" about your URL than '/users/123'? (just playing Devil's advocate) It just seems like '/foo/123/bar/123' is a lot easier than .one('foo', 123).one('bar', 123).Rigel
The idea is that at some point, you just know the entity name and the id. So you first do something lie var user = Restangular.one('users', 123).getList(). Later in the code or in some other controller, you do user.getList('buildings'). Here, you just know the next type which is buildings, but it queries /users/123/buildings/, so you don't have to know the full URL all of the timeLaster
Good but one-sided. The possible "irrelevance" of Restangular has been suggested in this thread in regard of recent enhancements of $resource - I don't imply it will become irrelevant by any mean, just that it has been mentioned. Any factual disadvantages or gotchas we should be aware of ?Uriia
i think one big advantage of restangular over ngresource is support.. really. think about it: ngresource is but a submodule amongst many more in angular.js.. restangular has its own github page.. i ran into issues with ngresource and asked about'em in the angular.js forum.. didn't get much attention..Thundercloud
isn't a lot of what is in that README outdated with a more current version of ngresource? (ie/ usage of promises, decorating response object via transformResponse)Adventurism
There is also a video parleys.com/play/535a189ee4b0c5ba17d43455/chapter38/aboutPanettone
B
8

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.

Bohlen answered 4/12, 2013 at 12:26 Comment(0)
A
3

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.

Arsenic answered 15/5, 2013 at 0:5 Comment(4)
1.1.3 $resource will return promises and can be implimented using latest PR commit. #16430332 Will future support be offered to $resource to support additional verbs? And if that happens Restangular seems like it will disappear and become irrelivant.Hanahanae
@DanKanze I am not sure about future support for additional verbs. For most use cases, the additional verbs are not necessary, so I wouldn't expect that to be built in any time soon, but that doesn't mean it won't happen.Arsenic
@DanKanze - I doubt it would become irrelevant. Restangular provides much better support for nested-resources, which is a requirement for some developers. Something that Ng-resource does not support particularly well. In addition, ng-resource also does not follow RESTful conventions, something I've spoken about on my blog.Fishplate
@Fishplate good point about nested resources mate, especially useful for Rails backends.Unstained
F
1

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.

Falcate answered 27/10, 2015 at 11:18 Comment(0)
P
0

For quick simple website that you want to run for ever with the minimum support I would use the built-in angular http HttpClient whoever when I'm working on a project that I love and I'm enjoying and trying to use all cool technologies then I'll use Ngx-Restangular

Also you should know that ngx-restangular work with RESTful services only as the name suggest. So for services that provide SOAP you will not be able to use Ngx-Restangular

https://ngx-restangular.com/

That being said I would use ngx-restangular most the time as I always try to work on project that I find cool and try to implement what I think is best.

Best of luck!

Pyle answered 19/9, 2018 at 17:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.