Remote Objects API

RemoteObjects(options)

Create a new RemoteObjects with the given options.

var remoteObjects = require('strong-remoting').create();
Arguments
Name Type Description
options Object

remoteObjects.adapter(name)

Get an adapter by name.

Arguments
Name Type Description
name String

The adapter name

remoteObjects.classes()

Get all classes.

remoteObjects.findMethod(methodString)

Find a method by its string name.

Example Method Strings:

  • MyClass.prototype.myMethod
  • MyClass.staticMethod
  • obj.method
Arguments
Name Type Description
methodString String

remoteObjects.methods()

List all methods.

remoteObjects.toJSON()

Get as JSON.

remoteObjects.before(methodMatch, hook)

Execute the given function before the matched method string.

Examples:

// Do something before our `user.greet` example, earlier.
remotes.before('user.greet', function (ctx, next) {
  if((ctx.req.param('password') || '').toString() !== '1234') {
    next(new Error('Bad password!'));
  } else {
    next();
  }
});

// Do something before any `user` method.
remotes.before('user.*', function (ctx, next) {
  console.log('Calling a user method.');
  next();
});

// Do something before a `dog` instance method.
remotes.before('dog.prototype.*', function (ctx, next) {
  var dog = this;
  console.log('Calling a method on "%s".', dog.name);
  next();
});
Arguments
Name Type Description
methodMatch String

The glob to match a method string

hook Function
Callback
Name Type Description
ctx Context

The adapter specific context

next Function

Call with an optional error object

method SharedMethod

The SharedMethod object

remoteObjects.after(methodMatch, hook)

Execute the given hook function after the matched method string.

Examples:

// Do something after the `speak` instance method.
// NOTE: you cannot cancel a method after it has been called.
remotes.after('dog.prototype.speak', function (ctx, next) {
  console.log('After speak!');
  next();
});

// Do something before all methods.
remotes.before('**', function (ctx, next, method) {
  console.log('Calling:', method.name);
  next();
});

// Modify all returned values named `result`.
remotes.after('**', function (ctx, next) {
  ctx.result += '!!!';
  next();
});
Arguments
Name Type Description
methodMatch String

The glob to match a method string

hook Function
Callback
Name Type Description
ctx Context

The adapter specific context

next Function

Call with an optional error object

method SharedMethod

The SharedMethod object

remoteObjects.invokeMethodInContext(ctx, method, cb)

Invoke the given shared method using the supplied context. Execute registered before/after hooks.

Arguments
Name Type Description
ctx
method
cb