AngularJS service to handle Rest API Restful Resources properly and easily
AngularJS service to handle Rest API Restful Resources properly and easily
Restangular is an AngularJS service that simplifies common GET, POST, DELETE, and UPDATE requests with a minimum of client code. It's a perfect fit for any WebApp that consumes data from a RESTful API.
Note This version of Restangular only supports Angular 1. For an Angular 2+ version of Restangular, check out ngx-restangular. It's a separate project with different maintainers, so issues regarding ngx-restangular should be reported over there :wink:
Learn Restangular! Try the live demo on plunkr. It uses the same example as the official Angular Javascript Project, but with Restangular! Or watch a video introduction of a talk I gave at Devoxx France about Restangular.
Restangular has several features that distinguish it from $resource:
$routeProvider.resolve and you'll get the real object injected into your controller if you want.$resource bugs. Restangular doesn't have problem with trailing slashes, additional : in the URL, escaping information, expecting only arrays for getting lists, etc.Let's see a quick and short example of these features
…`
You can download this by:
bower install restangularnpm install restangular
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/restangular/1.5.1/restangular.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/restangular/1.5.1/restangular.min.js"></script>Restangular depends on Angular and Lodash (or Underscore).
Each time, there're more Production WebApps using Restangular. If your webapp uses it and it's not in the list, please create an issue or submit a PR:
This is all you need to start using all the basic Restangular features.
// Add Restangular as a dependency to your app
angular.module('your-app', ['restangular']);
// Inject Restangular into your controller
angular.module('your-app').controller('MainCtrl', function($scope, Restangular) {
// ...
});The Restangular service may be injected into any Controller or Directive :) Note: When adding Restangular as a dependency it is not capitalized 'restangular' But when injected into your controller it is 'Restangular'
There are 3 ways of creating a main Restangular object. The first one and most common one is by stating the main route of all requests. The second one is by stating the main route and object of all requests.
// Only stating main route
Restangular.all('accounts')
// Stating main object
Restangular.one('accounts', 1234)
// Gets a list of all of those accounts
Restangular.several('accounts', 1234, 123, 12345);Now that we have our main Object let's start playing with it.
…`
Restangular comes with defaults for all of its properties but you can configure them. So, if you don't need to configure something, there's no need to add the configuration.
You can set all these configurations in **RestangularProvider or Restangular service to change the global con
Bad error message for .get(null)
plain() method removes fields that was added to data in addResponseInterceptor
Support DELETE method with body
Deprecated?
setPlainByDefault does not strip etag from responses
`plain()` doesn't remove custom methods
Multiple remove on Restangular
Dealing with single resources
Tests fail with Angular 1.6
make etag a strong etag when used in if-None-Match