New features on Restangular: the ultimate Rest API client for Angular

posted in: AngularJS, Javascript | 16

Hey,

I’ve been working more and more on Restangular and added a bunch of more features. You don’t know about it yet? Click here to find out @Github

Let’s get down to business. What are the cool new features?

 

1) You can now do URL Building with Restangular:

Sometimes, we have a lot of entities names with their ids and we just want to fetch the later entity. In those cases, doing a request for everything to get the last entity is an overkill. For those cases, I’ve added the possibility to create URLs using the same API as creating a new Restangular object. This connections are created without doing any request. Let’s see how to do this:

2) Now you can manually run any custom Rest operation that’s not 100% Restful anyway.

Sometimes our APIs have other operations besides the regular one. For example /messages/123/archive or /messages/clear-all For those cases, we can now use Restangular anyway. Restangular provides a set of “customOPERATION” methods like customGET, customPOST, customGETLIST, customPUT. Let’s see an example

3) You can also create your own Restangular methods and extend it as you want.

Let’s assume that your API needs some custom methods to work. If that’s the case, always calling customGET or customPOST for that method with all parameters is a pain in the ass. That’s why every element has a addRestangularMethod method. This can be used together with the hook setOnElemRestangularized to do some neat stuff. Let’s see an example to learn this.

4) It’s now available in a CDN.

5) Now you can send your own Headers

Every method in Restangular now accepts custom Query parameters and custom Headers as parameters.

6) Now you can use any response format in Restangular

Let’s assume that you have a Response that’s actually wrapped in some Object with some Metadata and that your List of element isn’t an array. If that’s the case, you can now use Restangular anyway thanks to the responseInterceptor and the responseExtractor.

7) Restangularized promises

Now all promises are enhanced as well. You can for example add a new element to the promise of an array returned by getList without calling the then. It will return a new Promise of the edited array, which you can use in your view as Angular knows how to handle promises. Take a look

That’s it for now!

If you have ANY suggestion on something to add, please create an Issue at Github or comment it here

Share!Share on FacebookTweet about this on TwitterShare on RedditShare on Google+Share on LinkedInBuffer this pageEmail this to someoneFlattr the author