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.
register(name: string, definition: ControllerDefinition): void
Argument | Type | Description |
---|---|---|
name | string | Controller name |
handler | ControllerDefinition | Controller actions definition |
Usage #
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",
}
}
}
}
}
}
}]
}
}
})
Edit this page on Github (opens new window)