Core
Framework v2.x
2

register() #

Available since 2.8.0

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',
        openapi: {
          description: "Simply say hello",
          parameters: [{
            in: "path",
            name: "name",
            schema: {
              type: "string"
            },
            required: true,
          }],
          responses: {
            200: {
              description: "Custom greeting",
              content: {
                "application/json": {
                  schema: {
                    type: "string",
                  }
                }
              }
            }
          }
        }
      }]
    }
  }
})