This is an Angular module which helps with RESTful data
1 person uses it
Author: 638fa0a11d0cb897a6dab71bfdcacf49? roypeled


A lightweight angular module that helps working with RESTful models. I was researching restangular and didn't like the fact that it was dependant on lodash and the dact that the models weren't configurable.

I liked ng-resources approach, but the implementation is horrible with nested objects.

So here is my solution.


To use this module you must add the JS file to your HTML and add ngNestedResource as a dependency to your app: ```html <!DOCTYPE html> ...

Basic root object

Nested resource is using angular's own resource module as a scaffolding. So you can use the original resource configuration: ```js

var organizations = nestedResource("/api/organizations/", { getAll: {method: "GET", isArray: true}, create: {method: "POST"} });

organizations.getAll(); // GET: "/api/organizations/" organizations.create({name: ""}); // POST: "/api/organizations/", payload: "{name: ''}" // returns { id:1, name: ""}

When specifying a route to an action you can add a wildcard (@) which will be replaced with the parameter supplied to the action.

Extending a nested object

You can nest objects using the 'nested' property, and just follow the same pattern inside.

Async Handling

Since this module is using resource, all requests are handled with $q's promises.

comments powered by Disqus
This page was last updated over 4 years ago.