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>;| Arguments | Type | Description |
|---|---|---|
request | KuzzleRequest | The 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
executefunction returns nothing, and the callback is called once the API call is finished, with the following arguments:callback(error, request) - otherwise: the
executefunction 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 the response part of
// it (accessible through the "request.response" property).
await context.accessors.execute(request);