Clients can search for and change resources exposed by a data service, in a way that each request type maps to a single HTTP request/response exchange. As these request types are based on HTTP, the usual HTTP services are also available, such as caching. In this context clients of a data service can collect or “batch up” several requests and then send that batch to the data service in a single HTTP request.
You can use
$batch
to collect a fixed number of operations (retrieve, create, update, delete) of an OData service in one single HTTP POST request.
Batch Request
An OData batch request is represented as a multipart MIME v1.0 message (see
RFC2046
under
http://www.rfc-editor.org/rfc/rfc2046.txt
), a standard format allowing the representation of multiple parts, each of which may have a different content type, within a single request.
Batch requests allow grouping of multiple operations (as described in
OData: Operations
under
http://www.odata.org/documentation/operations
) into a single HTTP request payload.
Batch requests are submitted as a single HTTP POST request to the
$batch
endpoint of a service as described in
OData: URI Conventions
under
http://www.odata.org/documentation/uri-conventions
.
The body of a batch request is made up of an ordered series of retrieve operations and/or change sets. A change set is an atomic unit of work that is made up of an unordered group of one or more of the insert, update or delete operations. Change sets cannot contain retrieve requests and cannot be nested, that is, a change set cannot contain a change set.
In the batch request body, each retrieve request and change set is represented as a distinct MIME part and is separated by the boundary marker defined in the Content-Type header of the request. The contents of the MIME part which represents a change set is itself a multipart MIME document with one part for each operation that makes up the change set.
Each MIME part representing a retrieve request or change set within the batch includes both Content-Type and Content-Transfer-Encoding MIME headers as seen in the examples below. The batch request boundary is the name specified in the Content-Type Header for the batch.
For more information, see
http://www.odata.org/documentation/operations
.
Batch Response
The batch response contains a Content-Type header specifying a content type of multipart/mixed and a batch boundary specification, which may be different from the batch boundary that was used in the corresponding request.
Within the body of the batch response is a response for each retrieve request and change set that was in the associated batch request. The order of responses in the response body must match the order of requests in the batch request. Each response includes a Content-Type header with a value of
application/http
, and a Content-Transfer-Encoding MIME header with a value of
binary
.
A response to a retrieve request is formatted exactly as it would have appeared outside of a batch.
The body of a change set response is either a response for all the successfully processed change request within the change set, formatted exactly as it would have appeared outside of a batch, or a single response indicating a failure of the entire change set.
If the set of HTTP request headers of a batch request are valid, the HTTP response status code is always 202 (Accepted). This is irrespective of whether some retrieve operations or change sets within this batch request fail or not.
As defined in the OData specification for batch processing , in case an operation within a change set fails the batch response body contains only one single response for this change set indicating the failure of the entire change set.
For more information, see
http://www.odata.org/documentation/operations
.
Handling Operations in Batch Requests
Each retrieve operation such as Read Entry or Read Feed within a
$batch
request will be transferred separately from the SAP NetWeaver Gateway hub system to the provider application in the backend system for processing.
Every change set is treated as one Logical Unit of Work (LUW), ensuring its “all or nothing” character. All operations of a change set will be sent at once from the SAP NetWeaver Gateway hub system to the provider application in the backend system for processing.
Results of all operations will be collected at the SAP NetWeaver Gateway hub system and sent as one HTTP response to the OData consumer.