Introducing the ngResource module
In Chapter 7, Introduction to AngularJS, we mentioned the $http
service as means of communication between the AngularJS application and your backend API. While the $http
service provides the developer with a low-level interface for the HTTP request, the AngularJS team figured out they could better help developers when it comes to RESTful APIs. Since the REST architecture is well structured, much of the client code dealing with AJAX requests could be obfuscated using a higher-level interface. For this purpose, the team created the ngResource
module, which provides the developer with an easy way to communicate with a RESTful data source. It does so by presenting a factory, which creates an ngResource
object that can handle the basic routes of a RESTful resource. We'll explain how it works in next sections but ngResource
is an external module, so first you'll need to install it using Bower.
Installing the ngResource module
Installing the ngResource
module is...