Optional Use bower to retrieve package
Include angular module
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
$search can be used.
To reload a collection use
$refresh. To append more results use
To update an object, just modify the properties and call
To create a new object use
$build and then call
$save to send a POST request to the server.
Finally, to destroy an object just call
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
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:
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.
$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:
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).
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
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
Serialization: Encoding and Decoding
Hooks and Callbacks
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.