Domanda

For getting SharePoint list values through rest. I came through two solutions

  1. writing CAML Query in the body of AJAX call
    1. Odata query selector operators(eq: select,expand) in the url

Which is better way.Suggest advantages and disadvantages. Any solution will be appreciated.

È stato utile?

Soluzione

A few benefits of REST ODATA queries:

  • Much easier to write.
  • Generally more readable and obvious to another developer.
  • Might be a tiny bit faster, but probably not enough to notice. (The ODATA query and the CAML query are both processed on the server.)
  • Easy to create and test as an HTTP GET.

A few benefits of CAML queries:

  • You can create more complex queries.
  • You can query on properties that may not be exposed by ODATA.
  • The query does not have to be part of the URL, therefore is more secure, especially with HTTPS.
  • The query does not have to be part of the URL, therefore has no length limitations. (Even when part of the query string, it must be sent as an HTTP POST as you need to include the "X-RequestDigest".)
  • Can be intermixed with ODATA commands ($select, etc) when used GetItems.
  • Supports CAML recursive.

    Example of a more complex REST query that uses both CAML and ODATA to get all folders and subfolders in a library:

    /sites/yourSite/_api/web/lists/getbytitle('Documents')/GetItems(query=@v1)?@v1={'ViewXml':'<View Scope=\'RecursiveAll\'><Query><Where><Eq><FieldRef Name=\'FSObjType\' ></FieldRef><Value Type=\'LookUp\'>1</Value></Eq></Where></Query></View>'}&$select=FileDirRef,fileleafref

    Method: POST

    Header: {"accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose", "content-length":len, "X-RequestDigest": "yourRequestDigest"}

I generally use CAML queries only when I can't use ODATA queries.

The above all assumes we are talking about the SharePoint REST API.

Altri suggerimenti

Based on my experience, I think Odata query selectors are better in performance. As it gets only those particular data.

However, in case of Caml query, it gets the data based on the rest url and then filters based on the query which loses the performance.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top