cloud-cap-samples
cloud-cap-samples copied to clipboard
Add multiple books as one JSON batch request
For me it was not obvious how I could POST multiple books as part of one request. I got hinted to the OData specification where I was able to find some information on this. I would suggest we add a sample $batch request to our prominent bookshop sample, so that it is easier for beginners to understand this concept.
Thanks @GitP4tt @hm23 can you check if this is proper JSON batch? @beckermarc I guess this is not supported yet on Java, right? Then we should add a comment hint in the example.
I guess this is not supported yet on Java, right? Then we should add a comment hint in the example
No, Java only supports multipart batch requests. It doesn't support the JSON format.
I guess this is not supported yet on Java, right? Then we should add a comment hint in the example
No, Java only supports multipart batch requests. It doesn't support the JSON format.
I can look into it and try to refactor the JSON batch into a multipart batch request. That should work for both stacks, shouldn't it?
Should add: it's pretty poor that OData doesn't support creating multiple rows by one request other than through $batch requests. CAP does btw:
INSERT.into (Books) .entries ([/* ... → all of same kind */])
srv.create (Books) .entries ([/* ... → all of same kind */])
These requests can be sent as single operations and delegated to databases in single prepared statements.
In contrast to that OData $batches can contain arbitrary mixes of queries → no guaranteed way to optimise.
One more comment: as also discussed in other forums, a better way to do bulks inserts in OData would actually be through actions accepting arrays of entities or deep inserts of fake entities. E.g. modelled in CDS:
service Sue {
entity Foo {...} // OData does not support bulk inserts
entity Dummy { foos: Composition of many Foo } // Deep insert would allow bulk insert
action AddFoos (foos : many Foo); // Action for bulk insert
}
Both need custom coding though
Hey Heiko @hm23 :)
Could you have a look at the JSON batch? I've of course tested it, but let me know if this can be improved.