restangular: Differences with $resource 接上篇Something about http request in angularjs
2014-11-24 13:59
701 查看
转自:https://github.com/mgonto/restangular/blob/master/README.md#differences-with-resource
Differences with $resource
Restangular has several features that distinguish it from $resource:It uses promises. Instead of doing the "magic" filling of objects like $resource,
it uses promises.
You can use this in $routeProvider.resolve. As Restangular returns promises, you can return any of the methods in the
$routeProvider.resolveand
you'll get the real object injected into your controller if you want.
It doesn't have all those
$resourcebugs. Restangular
doesn't have problem with trailling slashes, additional
:in the URL, escaping information, expecting only
arrays for getting lists, etc.
It supports all HTTP methods.
It supports ETag out of the box. You don't have to do anything. ETags and If-None-Match will be used in all of your requests
It supports self linking elements If you receive from the server some item that has a link to itself, you can use that to query the server instead of writing the URL manually.
You don't have to create one $resource object per request. Each time you want to do a request, you can just do it using the object that was returned by Restangular. You don't need to create a new object for this.
You don't have to write or remember ANY URL. With $resource, you need to write the URL Template. In here, you don't write any urls. You just write the name of the resource you want to fetch and that's it.
It supports nested RESTful resources. If you have Nested RESTful resources, Restangular can handle them for you. You don't have to know the URL, the path, or anything to do all of the HTTP operations you want.
Restangular lets you create your own methods. You can create your own methods to run the operation that you want. The sky is the limit.
Support for wrapped responses. If your response for a list of element actually returns an object with some property inside which has the list, it's very hard to use $resource. Restangular knows that and it makes it easy on
you. Check out https://github.com/mgonto/restangular#my-response-is-actually-wrapped-with-some-metadata-how-do-i-get-the-data-in-that-case
You can build your own URLs with Restangular objects easily. Restangular lets you create a Restangular object for any url you want with a really nice builder.
Let's see a quick and short example of these features
// Restangular returns promises Restangular.all('users').getList() // GET: /users .then(function(users) { // returns a list of users $scope.user = users[0]; // first Restangular obj in list: { id: 123 } }) // Later in the code... // Restangular objects are self-aware and know how to make their own RESTful requests $scope.user.getList('cars'); // GET: /users/123/cars // You can also use your own custom methods on Restangular objects $scope.user.sendMessage(); // POST: /users/123/sendMessage // Chain methods together to easily build complex requests $scope.user.one('messages', 123).one('from', 123).getList('unread'); // GET: /user/123/messages/123/from/123/unread
相关文章推荐
- Something about http request in angularjs
- How to disable 'withcredentials' in HTTP header with node.js and Request package?
- No mapping found for HTTP request with URI [/operation-platform/js/displaytag.js] in DispatcherServl
- How to use $http and $resource in Angular JS
- Using HTTP Proxy in Node.js with request package
- SSM报错:No mapping found for HTTP request with URI [/smbms/js/echarts.js] in DispatcherServlet with na
- http://www.codeproject.com/Questions/117324/upload-file-in-c-with-HttpWebRequest
- Adding timeout support for http request in Node.JS
- springmvc No mapping found for HTTP request with URI in Dispatc
- securely implement request processing, filtering and content redirection with HTTP pipeline in ASP.NET
- 相对路径获取项目文件 及报错 No mapping found for HTTP request with URI XXX in DispatcherServlet with name ‘springmvc’解决方法
- No mapping found for HTTP request with URI [/MessBoard/login/images/bg_1.jpg] in DispatcherServlet w
- AngularJS Front-End App with Cloud Storage Tutorial Part 1: Building a Minimal App in Seven Steps
- No mapping found for HTTP request with URI [/cwgl/department/index] in DispatcherServlet with name
- 通过HTTP压缩来提高WebService性能的一些好资源(some good resource about WebService with HTTP-Compression )
- Part 17 Consuming ASP NET Web Service in AngularJS using $http
- Node.js Request Module…sending json in body for api request with put
- springmvc No mapping found for HTTP request with URI in Dispatc
- springmvc No mapping found for HTTP request with URI in Dispatc
- scala: How to write a simple HTTP GET request client in Scala (with a timeout)