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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.