Core
Framework v2.x
2

register() #

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

Registers a new API controller on the fly.

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

Copied to clipboard!
register(name: string, definition: ControllerDefinition): void

Argument Type Description
name
string
Controller name
handler
ControllerDefinition
Controller actions definition

Usage #

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

app.controller.register('greeting', {
  actions: {
    sayHello: {
      handler: async (request: KuzzleRequest) => `Hello, ${request.input.args.name}`,
      http: [{ verb: 'post', path: 'greeting/hello/:name' }]
    }
  }
})