configure #

Available since 2.11.0

Allows to configure how the API response should be sent to the requesting client.

Arguments #

configure(
  options: {
    headers?: JSONObject,
    status?: number,
    format?: 'standard' | 'raw',
    result?: any
  } = {}): void;

The optional options object may contain the following properties:

NameTypeDescription
(default)
headers
JSONObject
(null)
Additional response protocol headers, added with setHeaders
status
integer
KuzzleRequest status code, following the HTTP standard. When absent, a pending 102 status becomes 200 and any other status is kept
format
string
(null)
The response format, as a standard Kuzzle response or in a unwrapped raw format instead. When absent, the format is left unchanged
result
any
Available since 2.57.0
The response result. Set only when the property is present (result: null clears it). Unlike setResult, it does not reset the status: without a status option, a pending 102 becomes 200 and any other status is kept

Errors #

Both are thrown before anything is changed.

Example #

request.response.configure({
  headers: {
    'Location': 'http://kuzzle.io'
  },
  status: 302,
  format: 'raw',
});

// Set a result without touching the status already set on the request
request.response.configure({ result: { acknowledged: true } });