batch with AtomPub format possible?

Oct 23, 2012 at 11:31 AM

Hi Alex,

 

can datajs send a batch also with Atom/XML content for the data in the changesets?

I observed that the data is always in JSON Format e.g.:

 

--batch_ab58-7c73-33d5 Content-Type: multipart/mixed; boundary=changeset_9f66-3f75-31bb --changeset_9f66-3f75-31bb Content-Type: application/http Content-Transfer-Encoding: binary POST Products HTTP/1.1 Accept: application/atom+xml,application/atomsvc+xml,application/xml MaxDataServiceVersion: 2.0 DataServiceVersion: 2.0 Content-Type: application/json;odata=verbose {"ID":"9","Name":"Test","Description":"Description","ReleaseDate":"\/Date(1350943200000)\/","Price":"2","Rating":"3"} --changeset_9f66-3f75-31bb-- --batch_ab58-7c73-33d5--

Also I set the accept headers only to

 "application/atom+xml,application/atomsvc+xml,application/xml";

 Is that possible?

 

Oct 24, 2012 at 4:50 PM

Hi Joe,

   Yes, the thing is that you have to specify it on each request in the batch:

      var request = {
            requestUri: "http://temp.org",
            method: "POST",
            data: {
                __batchRequests: [
                    { requestUri: "http://feed(1)", headers: {} },
                    { requestUri: "http://feed(2)", headers: { "Accept": "application/json;odata=verbose" }, method: "GET" },
                    { __changeRequests: [
                        { requestUri: "http://feed(1)", headers: {}, method: "POST", data: testPayload },
                        { requestUri: "http://feed(2)", headers: { "Content-Type": "application/atom+xml", DataServiceVersion: "2.0" }, method: "PUT", data: testPayload }
                      ]
                    },
                    { requestUri: "http://feed(1)", headers: {} }
                ]
            }
        };

 



Also, the batch handler uses the library's default handler to serialize each individual request. You may also set the OData.defaultHandler object to  OData.atomHandler to get the same result.

Regards,

Alex Trigo.

Oct 25, 2012 at 10:38 AM

Thanks Alex, I got it working now.