Book Image

Data-oriented Development with AngularJS

Book Image

Data-oriented Development with AngularJS

Overview of this book

Table of Contents (17 chapters)
Data-oriented Development with AngularJS
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

The $resource service


When we have to deal with a RESTful API, $http proves to be rather low level. We might have to write a lot of boilerplate code to call the methods exposed by the API. This is where the $resource service comes in handy. It returns a resource object that has convenience methods that map to their HTTP verbs' counterparts. So, for example, the get method of the $resource service maps to the HTTP 'GET' method, the save method maps to POST, and the remove and delete methods map to DELETE. The query method maps to GET but has the isArray property set to true. This means it maps to a method that returns all the records (similar to get all).

Node.js and Express-based API sample

For this demo, I've written a small Node.js backend application that exposes a REST API for our Employee object used earlier. For simplicity, it just holds the data in memory and is for illustration purposes only. If you have an API ready, then you can skip this part and directly jump to the next section...