SDK
SDK Java v1.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

This SDK has been deprecated because of stability issues. It is not advised to use it in a production environment.

query #

Base method used to send queries to Kuzzle, following the API Documentation.

This is a low-level method, exposed to allow advanced SDK users to bypass high-level methods.

Signature #

io.kuzzle.sdk.KuzzleResponse query(io.kuzzle.sdk.KuzzleRequest request) throws io.kuzzle.sdk.BadRequestException, io.kuzzle.sdk.ForbiddenException, io.kuzzle.sdk.GatewayTimeoutException, io.kuzzle.sdk.InternalException, io.kuzzle.sdk.ServiceUnavailableException, io.kuzzle.sdk.NotFoundException, io.kuzzle.sdk.PartialException, io.kuzzle.sdk.PreconditionException, io.kuzzle.sdk.UnauthorizedException;
io.kuzzle.sdk.KuzzleResponse query(io.kuzzle.sdk.KuzzleRequest request, io.kuzzle.sdk.QueryOptions options) throws io.kuzzle.sdk.BadRequestException, io.kuzzle.sdk.ForbiddenException, io.kuzzle.sdk.GatewayTimeoutException, io.kuzzle.sdk.InternalException, io.kuzzle.sdk.ServiceUnavailableException, io.kuzzle.sdk.NotFoundException, io.kuzzle.sdk.PartialException, io.kuzzle.sdk.PreconditionException, io.kuzzle.sdk.UnauthorizedException;

Arguments #

ArgumentTypeDescriptionRequired
requestio.kuzzle.sdk.KuzzleRequestAPI request optionsyes
optionsio.kuzzle.sdk.QueryOptionsAdditional query optionsno

request #

A io.kuzzle.sdk.KuzzleRequest object containing the properties required for the Kuzzle API request. Each property can be accessed with standard getter/setter. The following properties are the most common.

PropertyTypeDescriptionRequired
controllerStringController nameyes
actionStringAction nameyes
bodyStringJSON query body for this actionno
indexStringIndex name for this actionno
collectionStringCollection name for this actionno
idStringid for this actionno
volatileStringJSON string representing additional information to send to Kuzzleno

options #

A io.kuzzle.sdk.QueryOptions object containing the additional options for this request. Each property can be accessed with standard getter/setter. The following properties are the most common.

PropertyTypeDescriptionDefault
queuablebooleanMake this request queuable or nottrue

Return #

A io.kuzzle.sdk.KuzzleResponse object containing the Kuzzle API response. See the API Documentation. The following properties are the most common.

PropertyTypeDescription
requestIdStringRequest unique id
resultStringRaw JSON result
errorStringError message
statusintRequest status (eg: 200, 403, etc.)

Exceptions #

Throws a io.kuzzle.sdk.KuzzleException if there is an error. See how to handle error.

Usage #

try {
  KuzzleRequest request = new KuzzleRequest();
  request.setController("document");
  request.setAction("create");
  request.setIndex("nyc-open-data");
  request.setCollection("yellow-taxi");
  request.setId("my-custom-document-id");
  request.setBody("{\"trip_distance\": 4.23, \"passenger_count\": 2}");
  QueryOptions options = new QueryOptions();
  options.setRefresh("wait_for");
  KuzzleResponse response = kuzzle.query(request, options);
  if (response.getStatus() == 200) {
    System.out.println("Document created");
  }
}
catch (UnauthorizedException e) {
  System.err.println("You are not connected");
}
catch (KuzzleException e) {
  System.err.println(e.getMessage());
}