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.
Expose SharedClass
.
Create a new SharedClass
with the given options
.
Name | Type | Description |
---|---|---|
name |
String
|
The |
constructor |
Function
|
The |
Name | Type | Description |
---|---|---|
ctor |
Function
|
The |
http |
Object
|
The HTTP settings |
Define a shared method with the given name.
Name | Type | Description |
---|---|---|
name |
String
|
The method name |
[options] |
Object
|
Set of options used to create a |
Find a sharedMethod with the given name or function object.
Name | Type | Description |
---|---|---|
fn |
String or Function
|
The function or method name |
[isStatic] |
Boolean
|
Required if |
Name | Type | Description |
---|---|---|
result |
SharedMethod
|
Get all shared methods belonging to this shared class.
Name | Type | Description |
---|---|---|
result |
Array.<SharedMethod>
|
An array of shared methods |
Define a shared method resolver for dynamically defining methods.
// below is a simple example
sharedClass.resolve(function(define) {
define('myMethod', {
accepts: {arg: 'str', type: 'string'},
returns: {arg: 'str', type: 'string'}
}, myMethod);
});
function myMethod(str, cb) {
cb(null, str);
}
Name | Type | Description |
---|---|---|
resolver |
Function
|
Create a new SharedMethod
with the given fn
.
Name | Type | Description |
---|---|---|
fn |
Function
|
The |
name |
String
|
The name of the |
sharedClass |
SharedClass
|
The |
options |
Object or Boolean
|
|
[options.isStatic] |
Boolean
|
Is the method a static method or a a |
[options.aliases] |
Array
|
A list of aliases for the |
[options.accepts] |
Array or Object
|
An |
[options.shared] |
Boolean
|
Default is |
[options.accepts.arg] |
String
|
The name of the argument |
[options.accepts.http] |
String
|
HTTP mapping for the argument |
[options.accepts.http.source] |
String
|
The HTTP source for the argument. May be one of the following:
|
[options.accepts.rest] |
Object
|
The REST mapping / settings for the argument. |
[options.returns] |
Array or Object
|
An |
Name | Type | Description |
---|---|---|
name |
String
|
The method name |
aliases |
Array.<String>
|
An array of method aliases |
isStatic |
Array or Object
|
|
accepts |
Array or Object
|
See |
returns |
Array or Object
|
See |
description |
String
|
|
http |
String
|
|
rest |
String
|
|
shared |
String
|
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
.
Name | Type | Description |
---|---|---|
result |
String
|
The type name |
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
|