Core
Framework v2.x
2

execute #

Executes a Kuzzle's API action.

This methods does not trigger API events or request:on* events.

Arguments #

execute(request: KuzzleRequest, callback?: any): Promise<KuzzleRequest>;

ArgumentsTypeDescription
requestKuzzleRequestThe API action to execute
callback
function
Callback to call with the API execution result
Deprecated since 2.8.0

Return #

The execute function resolves to an updated KuzzleRequest object, with its response part set.

How the response is returned depends whether a callback argument is provided:

  • if it is: the execute function returns nothing, and the callback is called once the API call is finished, with the following arguments: callback(error, request)
  • otherwise: the execute function returns a promise, resolving to the updated request, or rejected with a KuzzleError object

Example #

import { KuzzleRequest } from 'kuzzle';

const request = new KuzzleRequest({
  index: 'index',
  collection: 'collection',
  controller: 'document',
  action: 'get',
  _id: 'documentID'
});

// Mutates the provided KuzzleRequest object by updating its response part
// (accessible through the "request.response" property).
await context.accessors.execute(request);