Core
Framework v2.x
2

use() #

Available since 2.8.0

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)

use(controller: Controller): void

ArgumentTypeDescription
controller
Controller
Controller class extending the Controller abstract class

Usage #

import { KuzzleRequest, Controller } from 'kuzzle'

class EmailController extends Controller {
  constructor (app) {
    super(app)

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

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