Create a new RemoteObjects
with the given options
.
var remoteObjects = require('strong-remoting').create();
Name | Type | Description |
---|---|---|
options |
Object
|
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);
});
Note: the alias remotes.convert()
is deprecated.
Name | Type | Description |
---|---|---|
name |
String
|
The type name |
converter |
Function
|
Get an adapter by name.
Name | Type | Description |
---|---|---|
name |
String
|
The adapter name |
Add a shared class.
Name | Type | Description |
---|---|---|
sharedClass |
SharedClass
|
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 |
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 |
Get all classes.
Create a connection to a remoting server.
Name | Type | Description |
---|---|---|
url |
String
|
Server root |
name |
String
|
Name of the adapter (eg. "rest") |
Find a method by its string name.
Example Method Strings:
MyClass.prototype.myMethod
MyClass.staticMethod
obj.method
Name | Type | Description |
---|---|---|
methodString |
String
|
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
|
Invoke the given shared method using the supplied context. Execute registered before/after hooks.
Name | Type | Description |
---|---|---|
ctx |
|
|
method |
|
|
cb |
|
List all methods.
Get as JSON.
Create a new SharedMethod
with the given fn
.
Name | Type | Description |
---|---|---|
fn |
Function
|
The |
name |
Function
|
|
sharedClass |
SharedClass
|
The |
isStatic |
Boolean
|
Returns a reformatted Object valid for consumption as remoting function arguments
Create a new SharedMethod
with the given fn
. The function should include
all the method options.
Name | Type | Description |
---|---|---|
fn |
Function
|
|
name |
Function
|
|
SharedClass |
SharedClass
|
|
isStatic |
Boolean
|
Returns an appropriate type based on val
.
Returns a reformatted Object valid for consumption as JSON from an Array of
results from a remoting function, based on returns
.
Add an alias
Name | Type | Description |
---|---|---|
alias |
String
|
Get the function the SharedMethod
will invoke()
.
Execute the remote method using the given arg data.
Name | Type | Description |
---|---|---|
args |
|
{Object} containing named argument data |
fn |
|
{Function} callback |
Will this shared method invoke the given suspect
?
// examples
sharedMethod.isDelegateFor(myClass.myMethod); // pass a function
sharedMethod.isDelegateFor(myClass.prototype.myInstMethod);
sharedMethod.isDelegateFor('myMethod', true); // check for a static method by name
sharedMethod.isDelegateFor('myInstMethod', false); // instance method by name
Name | Type | Description |
---|---|---|
suspect |
String or Function
|
The name of the suspected function or a |
Create a new HttpContext
with the given options
.
Name | Type | Description |
---|---|---|
options |
Object
|
Inherit from EventEmitter
.
Build args object from the http context's req
and res
.
Finish the request and send the correct response.
Get an arg by name using the given options.
Name | Type | Description |
---|---|---|
name |
String
|
|
options |
Object
|
optional |
Invoke the given shared method using the provided scope against the current context.
Create a new HttpInvocation
.
Name | Type | Description |
---|---|---|
method |
String
|
|
args |
String
|
|
base |
String
|
Inherit from EventEmitter
.
Determine if the value matches the given accept definition.
Build args object from the http context's req
and res
.
Get an arg value by name using the given options.
Name | Type | Description |
---|---|---|
name |
String
|
Start the invocation.
Transform the response into callback arguments
Name | Type | Description |
---|---|---|
res |
HttpResponse
|
|
callback |
Function
|