Create a new RemoteObjects
with the given options
.
var remoteObjects = require('strong-remoting').create();
Name | Type | Description |
---|---|---|
options |
Object
|
Create a connection to a remoting server.
Name | Type | Description |
---|---|---|
url |
String
|
Server root |
name |
String
|
Name of the adapter (eg. "rest") |
Invoke a method on a remote server using the connected adapter.
Name | Type | Description |
---|---|---|
method |
String
|
The remote method string |
[ctorArgs] |
String
|
Constructor arguments (for prototype methods) |
[args] |
String
|
Method arguments |
[callback] |
Function
|
callback |
Name | Type | Description |
---|---|---|
err |
Error
|
|
arg... |
Any
|
Get an adapter by name.
Name | Type | Description |
---|---|---|
name |
String
|
The adapter name |
Get all classes.
Add a shared class.
Name | Type | Description |
---|---|---|
sharedClass |
SharedClass
|
Find a method by its string name.
Example Method Strings:
MyClass.prototype.myMethod
MyClass.staticMethod
obj.method
Name | Type | Description |
---|---|---|
methodString |
String
|
List all methods.
Get as JSON.
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();
});
Name | Type | Description |
---|---|---|
methodMatch |
String
|
The glob to match a method string |
hook |
Function
|
Name | Type | Description |
---|---|---|
ctx |
Context
|
The adapter specific context |
next |
Function
|
Call with an optional error object |
method |
SharedMethod
|
The SharedMethod object |
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();
});
Name | Type | Description |
---|---|---|
methodMatch |
String
|
The glob to match a method string |
hook |
Function
|
Name | Type | Description |
---|---|---|
ctx |
Context
|
The adapter specific context |
next |
Function
|
Call with an optional error object |
method |
SharedMethod
|
The SharedMethod object |
Invoke the given shared method using the supplied context. Execute registered before/after hooks.
Name | Type | Description |
---|---|---|
ctx |
|
|
method |
|
|
cb |
|
Define a named type conversion. The conversion is used when a
SharedMethod
argument defines a type with the given name
.
remotes.defineType('MyType', function(val, ctx) {
// use the val and ctx objects to return the concrete value
return new MyType(val);
});
Name | Type | Description |
---|---|---|
name |
String
|
The type name |
converter |
Function
|