execute #
Deprecated since 2.8.0
Use the sdk accessor instead, unless you need to execute the request with the context (user, connection) of the original one.
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
Errors #
| Error | Reason |
|---|---|
plugin.context.invalid_callback | callback is neither a function nor null/undefined (the error is returned as a rejected promise) |
plugin.context.missing_request | request is missing or empty |
plugin.context.unavailable_realtime | The request is a realtime:subscribe or realtime:unsubscribe action: use the subscription accessor instead |
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);