In this article we can see the when to use REST and when to use JSOM depending on the scenario.
REST is Representational State Transfer. REST is an architectural style and uses HTTP protocol. SharePoint 2013 onwards REST API is supported.
For filtering data, REST supports OData protocol.
One of the example of REST URL is given below:
You can find more REST examples from References.
1. Deeper understanding of the SharePoint CSOM API
3. CAML query used for filtering
Following is an example code for JSOM:
var listTitle = “Contacts”;
using(var context = new ClientContext(“http://url”))
var list = context.Web.Lists.GetByTitle(listTitle);
You can see References for source-code example.
Following are the advantages of going with REST:
1. REST web requests are easier to work with that we can use Browser to test them
2. No overheads of WSDL creation Or Detailed SharePoint knowledge required
3. No overheads of tying up with Service Reference
4. Direct Calls for fetch, insert, update, delete, find operations
5. Better Interoperability supporting different clients on different platforms, programming models
In this way REST is more preferred among SharePoint Programmers.
Following are the advantages of JSOM over REST which I would prefer to use only in particular scenarios.
1. JSOM supports Batching.
Batching is the technique of tying multiple queries and sending to server. In this way, the roundtrip can be reduced to one.
Scenario: You have a Web Page where 10 list items needs to be loaded. In the case of REST, this will require 10 roundtrips to the server. Right?
But if you are using JSOM, you can wrap all the queries into one roundtrip. Invoke the Load() method multiple times as shown below.
Then we can call the ExecuteQuery() method which will actually send the query to the server. This is the advantage of Batching in JSOM.
Chattier is another term which means the Opposite of Batching. Chattier means it requires chat like request-response between client & server. So REST is chattier & JSOM not.
In this article we can have explored the usage of REST vs. JSOM based on scenario.