Extending yarm

You can add new resource definition helpers to yarm with yarm.extend(), and the built-in native and mongoose helpers are actually defined this way. This is very useful when you use the same kind of resource customization on several resources.

yarm.extend("onlyOneProperty", function(path, object, property) {
  // Use this.sub(...) to define "root" resources
  var resource = this.sub(path)
    .get(function(req, cb) {
      cb(null, object[property]);

  // Remember to return the resource to enable method chaining
  return resource;

yarm.onlyOneProperty("path/to/object", { "rest": "Hey !" }, "rest");

app.use("/rest", yarm());
$ curl http://localhost/rest/path/to/object
Hey !