Batch and Composite Requests

Batch and composite APIs pose special challenges, because they handle multiple requests in a single call. Mobile SDK classes take the pain out of building and configuring these complex requests.

Batch and Composite Request Classes 

  • Request:

    • BatchRequest
    • CompositeRequest
  • Builder:

    • BatchRequestBuilder
    • CompositeRequestBuilder
  • Response:

    • BatchResponse
    • CompositeRequestBuilder

These classes make it easy to create batch and composite requests. To use them:

  1. Create a builder instance. For batch requests, you can optionally set haltOnError property to true:

    Kotlin

    1val builder = BatchRequest.BatchRequestBuilder()
    2// Optional; defaults to false
    3builder.setHaltOnError(true)
    Java

    1BatchRequest.BatchRequestBuilder builder =
    2    new BatchRequest.BatchRequestBuilder();
    3// Optional; defaults to false
    4builder.setHaltOnError(true);

    For composite requests, you can optionally set the allOrNone rollback property to true.

    Kotlin

    1val builder = CompositeRequest.CompositeRequestBuilder()
    2// Optional; defaults to false
    3builder.setAllOrNone(true)
    Java

    1CompositeRequest.CompositeRequestBuilder builder =
    2    new CompositeRequest.CompositeRequestBuilder();
    3// Optional; defaults to false
    4builder.setAllOrNone(true);
  2. As you create REST requests, add them to the builder object. For batch requests:

    Kotlin

    1builder.addRequest(request)
    Java

    1builder.addRequest(request);

    With composite requests, you also provide a reference ID as described in the REST API Developer Guide. You specify this ID when you add the RestRequest object:

    Kotlin

    1builder.addRequest(referenceId, request)
    Java

    1builder.addRequest(referenceId, request);
  3. When you’re ready, call the builder object’s build method:

    Kotlin

    1builder.build(ApiVersionStrings.VERSION_NUMBER)
    Java

    1builder.build(ApiVersionStrings.VERSION_NUMBER);

    Each build method returns a specialized RestRequest object (BatchRestRequest or CompositeRestRequest instance) that you can send through the shared RestClient.sendAsync() method.

    To use an older API version as the default argument, pass a literal string in the format “v42.0”.

    Tip

  4. Responses to batch and composite requests arrive as instances of the response class (BatchResponse or CompositeResponse).

See Also 

We've Moved

Welcome to the new home of the Mobile SDK Developer Guide! For now, the Japanese guide can be found in PDF form.