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.
Batch and Composite Request Classes
-
Swift
-
:
-
BatchRequest -
BatchRequestBuilder -
BatchResponse -
CompositeRequest -
CompositeRequestBuilder -
CompositeResponse
-
-
-
Objective-C
-
:
-
SFSDKBatchRequest -
SFSDKBatchRequestBuilder -
SFSDKBatchResponse -
SFSDKCompositeRequest -
SFSDKCompositeRequestBuilder -
SFSDKCompositeResponse
-
-
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
haltOnErrorproperty to true:let builder = BatchRequestBuilder() // Optional; defaults to false builder.setHaltOnError(true)For composite requests, you can optionally set the
allOrNonerollback property to true.let builder = CompositeRequestBuilder() // Optional; defaults to false builder.setAllOrNone(true) -
As you create REST requests, add them to the builder object.
builder.add(request as! BatchRequest)With composite requests, you also provide a reference ID as described in the REST API Developer Guide. You can add a base
RestRequestobject and specify the reference ID explicitly:builder.add(request, referenceId)or add a
CompositeSubRequestobject, which is aRestRequestobject that stores the reference ID internally:builder.add(request as! CompositeSubRequest) -
When you’re ready, call the builder object’s build method—
buildBatchRequest(_:)orbuildCompositeRequest(_:). For example:let request = builder.buildBatchRequest(SFRestDefaultAPIVersion)Each build method returns a specialized
BatchRestRequestorCompositeRestRequestobject. You can send these objects through the sharedRestClientinstance.tip: 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 (
BatchResponseorCompositeResponse).