Plugin #
Base class for External Plugins.
Plugins registered with the BackendPlugin.use method must extends this abstract class.
Some properties of the Plugin
class allows to define a set of features that will be integrated to the plugin.
api
#
This property allows to define plugin features.
Type | Description |
---|---|
PluginApiDefinition | Define new API controllers PluginApiDefinition |
The PluginApiDefinition
type is an object with each key as a controller name and the value is a valid ControllerDefinition.
type PluginApiDefinition = {
/**
* Name of the API controller.
*/
[controller: string]: ControllerDefinition
}
config
#
Type | Description |
---|---|
JSONObject | Plugin configuration |
context
#
Type | Description |
---|---|
PluginContext | PluginContext instance |
hooks
#
This property allows to define plugin features.
Type | Description |
---|---|
| Allows to define hooks on events |
The PluginHookDefinition
type is an object with each key as an event name and the value is a valid HookEventHandler.
export type PluginHookDefinition = {
/**
* Event name or wildcard event.
*/
[event: string]: HookEventHandler | HookEventHandler[]
}
pipes
#
This property allows to define plugin features.
Type | Description |
---|---|
| Allows to define pipess on events |
The PluginPipeDefinition
type is an object with each key as an event name and the value is a valid PipeEventHandler.
export type PluginPipeDefinition = {
/**
* Event name or wildcard event.
*/
[event: string]: PipeEventHandler | PipeEventHandler[]
}
strategies
#
This property allows to define plugin features.
Type | Description |
---|---|
StrategyDefinition | A valid StrategyDefinition object. |
controllers
#
Controllers should be defined in the api property.
This property is not available in Typescript.
Type | Description |
---|---|
object | Controllers definition object |
Example:
class MyPlugin {
init (config, context) {
this.controllers = {
greeting: {
sayHello: request => `Hello, ${request.input.args.name}`,
sayGoodbye: 'greetingSayGoodbye'
}
};
}
async greetingSayGoodbye (request) {
return `Goodbye, ${request.input.args.name}`
}
}
routes
#
Routes should be defined in the api property.
This property is not available in Typescript.
Type | Description |
---|---|
object | Routes definition object |
Example:
class MyPlugin {
init (config, context) {
this.controllers = {
greeting: {
sayHello: request => `Hello, ${request.input.args.name}`
}
};
this.routes = [
{ verb: 'get', path: '/greeting/:name', controller: 'greeting', action: 'sayHello' }
];
}
}