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.
- Swift
-
- Objective-C
-
These classes make it easy to create batch and composite requests. To use them:
-
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. -
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 aRestRequest
object that stores the reference ID internally: -
When you’re ready, call the builder object’s build method—
buildBatchRequest(_:)
orbuildCompositeRequest(_:)
. For example:Each build method returns a specialized
BatchRestRequest
orCompositeRestRequest
object. You can send these objects through the sharedRestClient
instance.To use an older API version as the default argument, pass a literal string in the format “v42.0”.
-
Responses to batch and composite requests arrive as instances of the response class (
BatchResponse
orCompositeResponse
).