Framework v2.x

use() #

Available since 2.8.0
Experimental: non-backward compatible changes or removal may occur in any future release.

Loads an API controller class into the application.

This method can only be used before the application is started.

The controller class must:

  • call the super constructor with the application instance
  • extend the Controller abstract class
  • define the definition property
  • (optional) define the name property

The controller name will be inferred from the class name in kebab-case unless the name property is defined. (e.g. PaymentSolutionController will become payment-solution)

Copied to clipboard!
use(controller: Controller): void

Argument Type Description
Controller class extending the Controller abstract class

Usage #

Copied to clipboard!
import { KuzzleRequest, Controller } from 'kuzzle'

class EmailController extends Controller {
  constructor (app) {

    this.definition = {
      actions: {
        send: {
          handler: this.send
  async send (request: KuzzleRequest) {
    // ...

app.controller.use(new EmailController(app))