Create a new SharedClass
with the given options
.
Name | Type | Description |
---|---|---|
name |
String
|
The |
constructor |
Function
|
The |
options |
Object
|
Additional options. |
Name | Type | Description |
---|---|---|
ctor |
Function
|
The |
http |
Object
|
The HTTP settings |
Normalize HTTP path.
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 |
Disable a sharedMethod with the given name or function object.
Name | Type | Description |
---|---|---|
fn |
String
|
The function or method name |
isStatic |
Boolean
|
Disable a static or prototype method |
Disable a sharedMethod with the given static or prototype method name.
Name | Type | Description |
---|---|---|
methodName |
String
|
The method name |
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
|
Find a sharedMethod with the given static or prototype method name.
Name | Type | Description |
---|---|---|
methodName |
String
|
The method name Find a static or prototype method with the given name. |
Name | Type | Description |
---|---|---|
result |
SharedMethod
|
Get a key for the given method.
Name | Type | Description |
---|---|---|
fn |
String
|
The function or method name. |
isStatic |
Boolean
|
True if the method is static. |
Get all shared methods belonging to this shared class.
Name | Type | Description |
---|---|---|
options |
|
{Object} |
options.includeDisabled |
|
{Boolean} include all methods, even disabled. |
Name | Type | Description |
---|---|---|
result |
Array.<SharedMethod>
|
An array of shared methods |
Define a shared method resolver for dynamically defining methods.
Name | Type | Description |
---|---|---|
resolver |
Function
|
The resolver function. |
// below is a simple example
sharedClass.resolve(function(define) {
define('myMethod', {
accepts: {arg: 'str', type: 'string'},
returns: {arg: 'str', type: 'string'}
errors: [ { code: 404, message: 'Not Found', responseModel: 'Error' } ]
}, myMethod);
});
function myMethod(str, cb) {
cb(null, str);
}
Create a new SharedMethod
(remote method) with the given fn
.
See also Remote methods.
Name | Type | Description |
---|---|---|
fn |
Function
|
The |
name |
String
|
The name of the |
sharedClass |
SharedClass
|
The |
options |
Object
|
See below. |
Name | Type | Description |
---|---|---|
[accepts] |
Array or Object
|
Defines either a single argument as an object or an ordered set of arguments as an array. |
[accepts.arg] |
String
|
The name of the argument. |
[accepts.description] |
String
|
Text description of the argument, used by API documentation generators like Swagger. |
[accepts.http] |
String
|
HTTP mapping for the argument. See argument mapping in the docs. |
[accepts.http.source] |
String
|
The HTTP source for the argument. May be one of the following:
|
[accepts.rest] |
Object
|
The REST mapping / settings for the argument. |
[accepts.type] |
String
|
Argument datatype; must be a Loopback type. |
[aliases] |
Array
|
A list of aliases for the method. |
[errors] |
Array or Object
|
Object or |
[http] |
Array
|
HTTP-only options. |
[http.errorStatus] |
Number
|
Default error status code. |
[http.path] |
String
|
HTTP path (relative to the model) at which the method is exposed. |
[http.status] |
Number
|
Default status code when the callback is called without an error. |
[http.verb] |
String
|
HTTP method (verb) at which the method is available. One of: get, post (default), put, del, or all |
[isStatic] |
Boolean
|
Whether the method is a static method or a prototype method. |
[returns] |
Array or Object
|
Specifies the remote method's callback arguments; either a single argument as an object or an ordered set of arguments as an array.
The Additionally, one of the callback arguments can have |
[shared] |
Boolean
|
Whether the method is shared. Default is |
[status] |
Number
|
The default status code. |
Name | Type | Description |
---|---|---|
name |
String
|
The method name. |
aliases |
Array.<String>
|
An array of method aliases. |
isStatic |
Boolean
|
Whether the method is static; from |
accepts |
Array or Object
|
See |
returns |
Array or Object
|
See |
errors |
Array or Object
|
See |
description |
String
|
Text description of the method. |
notes |
String
|
Additional notes, used by API documentation generators like Swagger. |
http |
String
|
|
rest |
String
|
|
shared |
String
|
|
[documented] |
Boolean
|
Default: true. Set to |
Returns a reformatted Object valid for consumption as remoting function arguments
Returns an appropriate type based on a type specifier from remoting metadata.
Name | Type | Description |
---|---|---|
type |
Object
|
A type specifier from remoting metadata, e.g. "[Number]" or "MyModel" from |
Name | Type | Description |
---|---|---|
result |
String
|
A type name compatible with the values returned by |
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
|
build conversion options from remote's' args
Name | Type | Description |
---|---|---|
arg |
Object
|
Definition of accepts/returns argument. |
Name | Type | Description |
---|---|---|
result |
Object
|
Options object to pass to type-converter methods, e.g |
Returns an appropriate type based on val
.
Name | Type | Description |
---|---|---|
val |
|
The value to determine the type for |
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
.
Coerce an 'accepts' value into its final type. If using HTTP, some coercion is already done in http-context.
This should only do very simple coercion.
Name | Type | Description |
---|---|---|
uarg |
|
Argument value. |
desc |
Object
|
Argument description. |
ctx |
Context
|
Remoting request context. |
Add an alias
Name | Type | Description |
---|---|---|
alias |
String
|
Alias method name. |
Get the function the SharedMethod
will invoke()
.
Execute the remote method using the given arg data.
Name | Type | Description |
---|---|---|
scope |
Object
|
|
args |
Object
|
containing named argument data |
remotingOptions |
Object
|
remote-objects options |
cb |
Function
|
callback |
Determine if this shared method invokes the given "suspect" function.
Name | Type | Description |
---|---|---|
suspect |
String or Function
|
The name of the suspected function or a |
Name | Type | Description |
---|---|---|
result |
|
Boolean True if the shared method invokes the given function; false otherwise. |
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
Determine if this shared method invokes the given "suspect" function.
Name | Type | Description |
---|---|---|
result |
|
Boolean True if the shared method invokes the given function; false otherwise. |
sharedMethod.isDelegateForName('myMethod'); // check for a static method by name
sharedMethod.isDelegateForName('prototype.myInstMethod'); // instance method by name
Create a new HttpContext
with the given options
.
Invoking a remote method via HTTP creates HttpContext
object.
Name | Type | Description |
---|---|---|
req |
Object
|
Express Request object. |
res |
Object
|
Express Response object. |
method |
Function
|
|
options |
Object
|
See below. |
Name | Type | Description |
---|---|---|
xml |
Boolean
|
Set to |
Utility functions to send response body
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.
Deciding on the operation of response, function is called inside this.done()
Create a new HttpInvocation
.
Name | Type | Description |
---|---|---|
method |
SharedMethod
|
|
[args] |
Array
|
|
base |
String
|
The base URL |
Name | Type | Description |
---|---|---|
base |
String
|
The base URL |
method |
SharedMethod
|
The |
args |
Array
|
The arguments to be used when invoking the |
eslint-disable one-var
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 argument value by name.
Name | Type | Description |
---|---|---|
name |
String
|
Name | Type | Description |
---|---|---|
result |
|
Value of specified argument. |
Get Response object
Start the invocation.
Transform the response into callback arguments
Name | Type | Description |
---|---|---|
res |
HttpResponse
|
|
callback |
Function
|