angular-restmod

REST API Backed Model Layer
Homepage:
9 people use it
Author: E7e8aaecc49505601bb6e4833b24915d?d=https%3a%2f%2fidenticons.github.com%2f4093402b933bfab917fcb31030d76963 platanus
Submitted by: C7237492f05a57f75c4987cbeef30a0d?d=https%3a%2f%2fidenticons.github.com%2f6c845280429d7a98dce4a9c009017769 iobaixas

Angular Restmod Build Status

Overview

WHOAMI???!

Getting Started

Optional Use bower to retrieve package

Include angular module

Basic usage

A new model type can be created using the $restmod.model method, it is recommended to put each model on a separate factory. The first argument for model is the resource URL, if not given the resource is considered anonymous, more on this later.

The generated model type provides basic CRUD operations to interact with the API:

To retrieve an object by ID use $find, the returned object will be filled with the response data when the server response is received.

To reload an object use $fetch. WARNING: This will overwrite modified properties.

To retrieve an object collection $collection or $search can be used.

To reload a collection use $refresh. To append more results use $fetch.

To update an object, just modify the properties and call $save.

To create a new object use $build and then call $save to send a POST request to the server.

Or use $create

Finally, to destroy an object just call $destroy.

All operations described above will set the $promise property. This property is a regular $q promise that is resolved when operation succeds or fail. It can be used directly or using the $then method.

Relations

Relations are defined in $restmod using the definition object. The $restmod.model method can take as argument an arbitrary number of definition objects, models and builder functions after the url (first argument), more on this later.

There are three types of relations:

HasMany

This is a hirearchical relation between a model instance and another model collection. The child collection url is bound to the parent url. The child collection is created at the same time as the parent, so it is available even is the parent is not resolved.

Calling $create on the collection will POST to the collection nested url.

If the child collection model is anonymous (no url given to model) then all CRUD routes for the collection items are bound to the parent. The example above would behave like this:

HasOne

This is a hirearchical relation between a model instance and another model instance. The child instance url is bound to the parent url. The child instance is created at the same time as the parent, so its available even if the parent is not resolved.

If the child object model is anonymous (no url given to model) then all CRUD routes are bound to the parent (same as hasMany).

belongsTo

This is a reference relation between a model instance and another model instance. The child instance is not bound to the parent and is generated after server response to a parent's $fetch is received. A key is used by default to bind child to parent. The key property name can be optionally selected using the key attribute.

This relation can be optionally defined as inline, this means that it is expected that the child object data comes inlined in the parent object server data. The inline property name can be optionally selected using the source attribute.

Serialization: Encoding and Decoding

Hooks and Callbacks

Extending

Plugins

TODO....

API Refrence: http://platanus.github.io/angular-restmod

Take a look at https://github.com/platanus/simple-restmod-demo for a VERY basic (and outdated) example.

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