Batch and Composite Requests

Batch and composite APIs pose special challenges, because they handle multiple requests in a single call. In Swift, Mobile SDK extensions reduce the pain of building and configuring these complex requests.



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:

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

  2. As you create REST requests, add them to the builder object.

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

    or add a CompositeSubRequest object, which is a RestRequestobject that stores the reference ID internally:

  3. When you’re ready, call the builder object’s build method—buildBatchRequest(_:) or buildCompositeRequest(_:). For example:

    Each build method returns a specialized BatchRestRequest or CompositeRestRequest object. You can send these objects through the shared RestClient instance.

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

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