Skip to content

Instantly share code, notes, and snippets.

@pfrazee
Last active August 29, 2015 13:57
Show Gist options
  • Save pfrazee/9649878 to your computer and use it in GitHub Desktop.
Save pfrazee/9649878 to your computer and use it in GitHub Desktop.
var myitems = [];
testserver.route('/protocol/crud-coll')
.link({ href: '/protocol/crud-coll', rel: 'self', title: 'My Collection' })
.protocol('stdrel.com/crud-coll', {
itemUrl: '/protocol/crud-coll/{id}',
validate: function(item, req, res) {
var errors = {};
if (!item.fname) errors.fname = 'Required.';
if (!item.lname) errors.lname = 'Required.';
return errors;
},
add: function(item, req, res) {
var addedItem = {
id: myitems.length,
fname: item.fname,
lname: item.lname,
};
myitems.push(addedItem);
return addedItem;
}
});
testserver.route('/protocol/crud-coll/:id')
.link({ href: '/protocol/crud-coll/:id', rel: 'self' })
.protocol('stdrel.com/crud-item', {
collUrl: '/protocol/crud-coll',
validate: function(item, req, res) {
var errors = {};
if (!item.fname) errors.fname = 'Required.';
if (!item.lname) errors.lname = 'Required.';
return errors;
},
get: function(id, req, res) {
return myitems[id];
},
put: function(id, values, req, res) {
myitems[id] = {
id: id,
fname: values.fname,
lname: values.lname
};
return true;
},
delete: function(id, req, res) {
delete myitems[id];
return true;
}
});
testserver.route('/protocol/transformer')
.link({ href: '/protocol/transformer', rel: 'self', title: 'ToUppercase Transformer' })
.protocol('stdrel.com/transformer', {
transform: function(chunk) { return chunk.toUpperCase(); }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment