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.