Request #
Object representation of a Kuzzle API call, to be used with the entryPoint.execute function.
That object is continuously updated to reflect the current state of the request, during its entire lifecycle.
For more information about this object, refer to its technical documentation.
Response headers #
Network protocol specific headers can be added to the response. If the protocol supports it, these headers are forwarded in the response sent to the client.
To customize the response content, read the RequestResponse documentation.
Constructor #
new Request(data, [options]);
Arguments | Type | Description |
---|---|---|
data | object | API call, following the same format than non-HTTP API calls |
options | object | Additional request context |
options #
The options
object can contain the following properties:
Properties | Type | Description |
---|---|---|
connection | object | Available since 1.4.1 Connection information (see the connection object documentation) |
connectionId | string | Deprecated since 1.4.1 Connection unique identifier |
error | KuzzleError ,Error | Sets the request response with the provided error |
requestId | string | User-defined request identifier |
result | * | Sets the request response with the provided result, and the request status is set to 200 |
status | integer | Request status, following the HTTP error code standard |
Properties #
Read-only:
Properties | Type | Description |
---|---|---|
context | <a href=https://github.com/kuzzleio/kuzzle-common-objects/blob/master/README.md#modelsrequestcontext>RequestContext</a> | General request information (logged user, network information, ...) |
error | [ KuzzleError`](/core/1/protocols/api/context/errors) | Request error |
input | <a href=https://github.com/kuzzleio/kuzzle-common-objects/blob/master/README.md#modelsrequestinput>RequestInput</a> | Input request representation |
response | <a href=https://github.com/kuzzleio/kuzzle-common-objects#requestresponse>RequestResponse</a> | Serialized request response |
result | * | Request result |
timestamp | integer | Request creation timestamp, in Epoch-millis format |
Writable:
Properties | Type | Description |
---|---|---|
id | string | User-defined request unique identifier |
status | integer | Request status code |
clearError #
Clears the error: sets the error
property to null
, and the request status to 200
.
serialize #
Serializes the request into into a pair of objects that can be sent across the network.
Example #
const foo = request.serialize();
const bar = new context.Request(foo.data, foo.options);
setError #
Adds an error to the request.
The request status is also updated to the error status.
Argument #
setError(error);
Arguments | Type | Description |
---|---|---|
error | [ KuzzleError](/core/1/protocols/api/context/errors), Error | Request error |
If a KuzzleError
object is provided, the request's status attribute is set to the error one.
Otherwise, the provided error is embedded into a InternalError object, and the request status is set to 500.
setResult #
Sets the request result.
Arguments #
setResult(result, [options]);
Arguments | Type | Description |
---|---|---|
result | * | Request result |
options | optional, object | Optional result configuration |
options #
The options
object can contain the following properties:
Properties | Type (default) | Description |
---|---|---|
headers | object | Network specific headers. Shortcut to the response header functions |
raw | boolean (false) | If true , instead of a standard kuzzle response, the result is sent as is to the client, without being interpreted |
status | integer (200) | Request status |