A plugin that adds an HTTP transport to a model.
$ component install component/model-http
var model = require('model');
var http = require('model-http');
/**
* User model.
*/
var User = model('user')
.use(http('/users'))
.attr('id')
.attr('name');
/**
* Usage...
*/
var user = new User({ name: 'Fred' });
user.save(function (err) {
if (err) throw err;
store('user', id);
});
/**
* Later...
*/
var id = store('user');
User.get(id, function (err, user) {
if (err) throw err;
render(user);
});
Return a plugin function for a given base
URL. For HTTP calls that required an identifier, the model's primary
key will be appended to the base
URL.
Get a model by id
and invoke fn(err, model)
.
Remove a model by id
and invoke fn(err, model)
.
Get all models and invoke fn(err, models)
.
Remove all models and optionally invoke fn(err)
.
Return the URL for a given model instance.
Check whether a model has been saved yet.
Save a model, optionally invoking fn(err)
.
Remove a model, optionally invoking fn(err)
.