SDK
SDK Javascript v6.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

useController #

Adds a new controller to the SDK.

See also:

Arguments #

useController (ControllerClass, accessor);

ArgumentTypeDescription
ControllerClass
Class
Controller class. Must inherit from BaseController
accessor
string
Accessor name for the controller in the Kuzzle object

Returns #

Returns the Kuzzle object.

Usage #

class TaxiController extends BaseController {
  constructor (kuzzle) {
    super(kuzzle, 'my-plugin/taxi');
  }
  enroll () {
    return this.query({
      action: 'enroll'
    });
  }
}
const kuzzle = new Kuzzle(
  new WebSocket('kuzzle')
);
// Add the custom SDK controller
kuzzle.useController(TaxiController, 'taxi');
const run = async () => {
  try {
    await kuzzle.connect();
    // Call the custom SDK controller action
    console.log(await kuzzle.taxi.enroll());
    console.log('Success');
  } catch (error) {
    console.error(error);
  } finally {
    kuzzle.disconnect();
  }
};
run();