Chapter 9Using REST APIs in Single Page Blogger

Applying $resource to Our App

Let's return to our Single Page Blogger app and use AngularJS's $resource to store all our blog posts on a remote server. I've developed a RESTful back end to store blog posts using Node.js and MongoDB. The app has been deployed to OpenShift Cloud and can be accessed at http://spblogger-sitepointdemos.rhcloud.com.

Here is what the API looks like:

URLHTTP VerbRequest BodyResult
/api/postsGETemptyReturns all posts
/api/postsPOSTJSON StringCreate new post
/api/posts/:idGETemptyReturns single post
/api/posts/:idPUTJSON StringUpdates existing post
/api/posts/:idDELETEemptyDeletes existing post

Note: Making Cross-domain API Calls

Normally you won't be able to make cross-domain ...

Get AngularJS: Novice to Ninja now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.