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

posted in: AngularJS, Javascript | 12

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!FacebookTwitterRedditGoogle+LinkedInbufferEmailflattr
  • Nik So

    Dude restangular? That’s it man, I don’t care if it works which I have no doubt it does, I am using it!

    • mgonto

      hahahaha thanks dude!

  • http://www.facebook.com/DistractedBySquirrels Sebastian Sebald

    Restangular is really awesome! :-O
    Just one Question: Does it work with(in) a resolve ($routeProvider)? Meaning does Restangular return a promise? I couldn’t find any info on that on GitHub. Would love some clarification :)

  • Dave Smith

    Definitely gonna check this out! Been looking for a non-sucktacular alternative to $resource.

    • mgonto

      That’s precisely why I did it. $resource needs MUCH love to be functional in my opinion.

  • Bill King

    I am going to start implementing this too. You hit at just the time I was running into a wall… MUCH THANKS for your work!

  • http://www.facebook.com/alxloiz Alex Loizou

    Great dude! I’m revamping major parts right now, this feels like a life saver!
    Cheers!

  • nalberg

    i just use amplifyjs… http://amplifyjs.com/api/request/

  • http://www.friv2friv3friv4.com/ friv 2 friv 3 friv 4

    That’s precisely why I did it. $resource needs MUCH love to be functional in my opinion.

  • finestglasses j.

    With the internet vendors severe prescribed eye glasses, you’ll get most of these Designer Glasses with means affordable prices than these with the actual physical retailers.