Core
Guides v2.x
2

Plugins Features #

Embedded SDK #

Plugins have access to an instance of the EmbeddedSDK to interact with Kuzzle throught the Plugin.context.accessors.sdk property.

API #

Plugins can declare new controllers and actions through the Plugin.api property.

API definition must be done in the constructor or in the plugin init method.

The PluginApiDefinition is an object which each key is a controller name and each value is a ControllerDefinition

Copied to clipboard!
class EmailPlugin extends Plugin {
  constructor () {
    super({ kuzzleVersion: '>=2.8 <3' });

    this.api = {
      greeting: {
        actions: {
          sayHello: {
            handler: async request => `Hello, ${request.input.args.name}`
          }
        }
      }
    };
  }
}

Plugin controller names will be prefixed by the plugin name.

With the example above, the controller name will be email/greeting

Like standard API actions, plugin custom API action will also trigger events.

See also the API Controllers guide.

Pipes and Hooks #

Plugins can register hooks and pipes on the Event System.

Hooks and pipes registration must be done in the constructor or in the plugin init method.

Copied to clipboard!
class MyPlugin extends Plugin {
  constructor () {
    super({ kuzzleVersion: '>=2.8 <3' });

    this.hooks = {
      'document:beforeCreate': async request => {}
    };

    this.pipes = {
      'server:afterNow': async request => request
    };
  }
}