0
votes

I am newbee for OData V4. I had implement CRUD Operation easily with Web API with oData V4.

But I do not understand that how can I perform batch request using JSON. I visited below links also :

http://www.odata.org/documentation/odata-version-3-0/batch-processing/ http://www.odata.org/documentation/odata-version-3-0/batch-processing/

But could not get idea to performing batch operation using JSON.

Below is code sample for perform multiple get.

 $.ajax({
    url: 'http://localhost:52603/odata/$batch',
    contentType: 'multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b', 
    data: {
        __batchRequests: [
            { requestUri: "Employee", method: "GET" },
            { requestUri: "Country", method: "GET" }
        ]
    },
    success: function (data) {
        alert(data);
        console.log(data);
    }
   });

Any kind of help would be appreciate.

1

1 Answers

1
votes

It is not clear from your question how you are trying to use ODATA batch request. But in general, you can sent POST request to batch end point of an ODATA service with POST data containing individual batch requests as change sets. For ex:

Request URL : http://localhost:52603/odata/$batch

Header: contentType: 'multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b'

POST Data :

--batch_36522ad7-fc75-4b56-8c71-56071383e77b
Content-Type: multipart/mixed; boundary=changeset_067e003e-eb9a-49a7-8ff7-4edc0e39f0f5

--changeset_067e003e-eb9a-49a7-8ff7-4edc0e39f0f5
Content-Type: application/http
Content-Transfer-Encoding: binary

GET http://localhost:52603/odata/Employee


--changeset_067e003e-eb9a-49a7-8ff7-4edc0e39f0f5
Content-Type: application/http
Content-Transfer-Encoding: binary

GET http://localhost:52603/odata/Country


--changeset_067e003e-eb9a-49a7-8ff7-4edc0e39f0f5--
--batch_36522ad7-fc75-4b56-8c71-56071383e77b--

OData specs has some details examples.