WaibuRestApi

WaibuRestApi class defniton. This class is used to create a REST API services for Waibu.

Constructor

new WaibuRestApi()

Constructor

Members

routePath

Generate the route path for a given name.

transformResult

Transform the result before sending the response.

Methods

(async) _handleError(err, req, reply) → {Object}

Handle general errors.

Parameters:
NameTypeDescription
errObject

The error object

reqObject

The request object

replyObject

The reply object

Returns:

The transformed result

Type: 
Object

(async) _handleNotFound(erropt, req, reply) → {Object}

Handle not found errors.

Parameters:
NameTypeAttributesDefaultDescription
errObject<optional>
{}

The error object

reqObject

The request object

replyObject

The reply object

Returns:

The transformed result

Type: 
Object

(async) _handleResponse() → {void}

Handle the response.

Returns:
Type: 
void

(async) _handleSubApp()

Handle sub-applications by collecting and registering their routes.

(async) _routeByModelBuilder(options) → {Object}

Build a route based on the model configuration.

Parameters:
NameTypeDescription
optionsObject

The options for building the route

Properties
NameTypeAttributesDescription
filestring

The file path of the model configuration

dirstring

The directory of the model configuration

pathPrefixstring

The path prefix for the route

nsstring

The namespace

parentstring<optional>

The parent namespace

Returns:

The built route

Type: 
Object

(async) _routeByVerb(options) → {Object}

Build a route based on the HTTP verb.

Parameters:
NameTypeDescription
optionsObject

The options for building the route

Properties
NameTypeAttributesDescription
filestring

The file path of the route configuration

appCtxObject

The application context

dirstring

The directory of the route configuration

pathPrefixstring

The path prefix for the route

nsstring

The namespace

aliasstring

The alias for the route

parentstring<optional>

The parent namespace

Returns:

The built route

Type: 
Object

(async) _serveRoute(options) → {Object}

Serve a route.

Parameters:
NameTypeDescription
optionsObject

The options for serving the route

Properties
NameTypeAttributesDescription
modObject

The module object

nsstring

The namespace

parentstring<optional>

The parent namespace

Returns:

The served route

Type: 
Object

docSchemaDescription(method) → {string}

Generate the schema description for a given method.

Parameters:
NameTypeDescription
methodstring

The method name

Returns:

The schema description

Type: 
string

(async) docSchemaForFind(items) → {Object}

Generate the schema for the "find" operation.

Parameters:
NameTypeDescription
itemsObject

The items schema

Returns:

The schema for the "find" operation

Type: 
Object

(async) docSchemaGeneral() → {Object}

Generate the general schema for the API responses.

Returns:

The general schema for API responses

Type: 
Object

(async) docSchemaLib(name, obj)

Add a schema to the library.

Parameters:
NameTypeDescription
namestring

The name of the schema

objObject

The schema object

(async) docSchemaModel(param0) → {Object}

Generate the schema for a model method.

Parameters:
NameTypeDescription
param0Object

The parameters for generating the schema

Properties
NameTypeAttributesDefaultDescription
modelstring

The model name

methodstring

The method name

optionsObject<optional>
{}

Additional options for schema generation

Returns:

The generated schema

Type: 
Object

(async) docSchemaParams(paramName, …args) → {void}

Generate the schema for query parameters.

Parameters:
NameTypeAttributesDescription
paramNamestring

The name of the parameter

argsstring<repeatable>

The arguments for the parameter schema

Returns:
Type: 
void

(async) docSchemaQs(paramName, …args) → {void}

Generate the schema for query string parameters.

Parameters:
NameTypeAttributesDescription
paramNamestring

The name of the parameter

argsstring<repeatable>

The arguments for the parameter schema

Returns:
Type: 
void

(async) init()

Initialize the plugin.