Performance will be better using CSOM or REST API to retrieve data from 4 lists simultaneously.?

Dilip Kumar Yadav picture Dilip Kumar Yadav · Jan 14, 2016 · Viewed 7.2k times · Source

I am developing Sharepoint hosted app, and there is a situation where i need to get the data from 4 lists simultaneously, then use it later on. I am able to do it using CSOM. But performance wise what will be better CSOM or REST API. If rest API is the better approach then how can i do it.?

Answer

egidiocs picture egidiocs · Mar 20, 2016

My approach for SharePoint-hosted add-in is to use

a. REST API when requesting:

  • Single Element / Single Collection retrieval (single List, single ListColletion, single ListItem, single ListItemCollection, single Field, single FieldCollection etc.)
  • Large Datasets
  • Two things to consider when using REST API:
  • i. I do prefer using sp.RequestExecutor.js to executeQueryAsync over $Ajax calls. Reason #1: developing addins that interacts with other Site Collections or sibling webs. Reason #2: your X-RequestDigest header is resolved natively.
  • ii. Choose wisely your odata value in the Accept: application/json; odata=? header. odata=verbose is, well, verbose, meaning that it returns A LOT of generally unuseful metadata information that slow down responses. odata=mininalmetadata is a good choice for when you need a single metadatata information. odata=nometadata is what you generally need. Note that the object returned varies. While in verbose mode: obj.body.d.results. For the two other methods, obj.body.value

b. I use JSOM API when I need to:

  • Request ==at once== more than one List or ListItem, or need to load into the context different elements.
  • Batch updates

REST odata variation References:

https://blogs.msdn.microsoft.com/brian_farnhill/2014/03/11/approaches-to-optimising-sharepoint-client-side-communication/

http://www.andrewconnell.com/blog/sharepoint-2013-csom-vs.-rest-...-my-preference-and-why

http://blog.mannsoftware.com/?p=1521

https://blogs.office.com/2014/08/13/json-light-support-rest-sharepoint-api-released/

http://www.odata.org/documentation/odata-version-2-0/overview/

https://msdn.microsoft.com/en-us/library/office/dn168907.aspx

http://www.vrdmn.com/2013/07/batch-operations-using-javascript.html