odata batch processing

11
ODATA Batch Processing

Upload: ashish-agrawal

Post on 12-Jul-2015

123 views

Category:

Technology


6 download

TRANSCRIPT

Page 1: Odata batch processing

ODATA Batch Processing

Page 2: Odata batch processing

Sending multiple operation

request using a single http

request

Page 3: Odata batch processing

Sending Batch Request

Batch request allows grouping multiple operation in a single http request

Batch request is represented as a multipart MIME request with specific

headers and body part

Page 4: Odata batch processing

Batch Request headers

Batch request is submitted as a single POST request

Batch request should point to the URI : <Service Root URI>/$batch

Batch request should have a Content-Type header specifying a content type of

“multipart/mixed” and a boundary specification.

Eg: Content-Type: multipart/mixed; boundary=batch_36522ad7-fc75-4b56-

8c71-56071383e77b

The number here represent a guid

Page 5: Odata batch processing

Batch Request body

The body of the batch request should be made up of ordered sequence of

operations and/or changeset

In the batch request body every operation and changeset is represented with

a specific mime-type

A MIME part representing a query operation MUST include a Content-Type

header with value “application/http” and a Content-Transfer-

Encoding“ header with value ”binary”.

Page 6: Odata batch processing

Sample Request body POST /service/$batch HTTP/1.1

Host: host

Content-Type: multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b

--batch_36522ad7-fc75-4b56-8c71-56071383e77b

Content-Type: application/http

Content-Transfer-Encoding:binary

GET /service/Customers('ALFKI')

Host: host

--batch_36522ad7-fc75-4b56-8c71-56071383e77b

Content-Type: multipart/mixed; boundary=changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621

Content-Length: ###

-changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621

Content-Type: application/http

Content-Transfer-Encoding: binary

POST /service/Customers HTTP/1.1

Host: host

Content-Type: application/atom+xml;type=entry

Content-Length: ###

<AtomPub representation of a new Customer>

Page 7: Odata batch processing

Sample Request body Cont.

--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621

Content-Type: application/http

Content-Transfer-Encoding:binary

PUT /service/Customers('ALFKI') HTTP/1.1

Host: host

Content-Type: application/json

If-Match: xxxxx

Content-Length: ###

<JSON representation of Customer ALFKI>

--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621--

--batch_36522ad7-fc75-4b56-8c71-56071383e77b

Content-Type: application/http

Content-Transfer-Encoding:binary

GET service/Products HTTP/1.1

Host: host

--batch_36522ad7-fc75-4b56-8c71-56071383e77b--

Page 8: Odata batch processing

Responding to a Batch Request

A batch response body MUST match one-to-one with the corresponding batch request body, such that the same multipart MIME message structure defined for requests is used for responses

The order of ChangeSets and query operations in a Batch request is significant as a service MUST process the components of the Batch in the order recieved.

All operations in a ChangeSet represent a single change unit so a service MUST successfully process and apply all the requests in the ChangeSet or else apply none of them.

If the service receives a Batch request with an invalid set of headers it MUST return a 4xx response code and perform no further processing of the request.

If the set of request headers of a Batch request are valid (the Content-Type is set to multipart/mixed, etc) the service MUST return a 2xx Success HTTP response code

Page 9: Odata batch processing

Sample Response HTTP/1.1 202 Accepted

DataServiceVersion: 1.0

Content-Length: ####

Content-Type: multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b

--batch_36522ad7-fc75-4b56-8c71-56071383e77b

Content-Type: application/http

Content-Transfer-Encoding: binary

HTTP/1.1 200 Ok

Content-Type: application/atom+xml;type=entry

Content-Length: ###

<AtomPub representation of the Customer entity with EntityKey ALFKI>

--batch_36522ad7-fc75-4b56-8c71-56071383e77b

Content-Type: multipart/mixed; boundary=changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621

Content-Length: ###

--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621

Content-Type: application/http

Content-Transfer-Encoding: binary

Page 10: Odata batch processing

Sample Response HTTP/1.1 201 Created

Content-Type: application/atom+xml;type=entry

Location: http://host/service.svc/Customer('POIUY')

Content-Length: ###

<AtomPub representation of a new Customer entity>

--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621

Content-Type: application/http

Content-Transfer-Encoding: binary

HTTP/1.1 204 No Content

Host: host

--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621--

--batch_36522ad7-fc75-4b56-8c71-56071383e77b

Content-Type: application/http

Content-Transfer-Encoding: binary

HTTP/1.1 404 Not Found

Content-Type: application/xml

Content-Length: ###

--batch_36522ad7-fc75-4b56-8c71-56071383e77b--

Page 11: Odata batch processing

Thanks

Ashish Agrawal

[email protected]