Thursday, January 4, 2018

REST Or JSOM



REST

REST is Representational State Transfer. It 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:

http://server/_api/web/lists


JSOM

JSOM (JavaScript Object Model) is a CSOM (Client Side Object Model) interacting with SharePoint. This programming way is available from SharePoint 2010 onwards. JSOM programming requires the following:
  1. Deeper understanding of the SharePoint CSOM API.
  2. Reference to JSOM JavaScript files.
  3. CAML query used for filtering.
Here's an example code for JSOM:
.          var listTitle = "Contacts";  
.          using(var context = new ClientContext(“http://url”))  
.          {  
.             var list = context.Web.Lists.GetByTitle(listTitle);  
.             context.Load(list);  
.             context.ExecuteQuery();  
.          }  
REST Advantages

The 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, and find operations.
  5. Better Interoperability supporting different clients on different platforms, programming models.

    In this way REST is more preferred among SharePoint Programmers.
JSOM Advantages

The following are the advantages of JSOM over REST which I would prefer to use only in particular scenarios.
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 need 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.
  1. context.Load(list1);  
  2. context.Load(list2);  
  3. context.Load(list10);  
Then we can call the ExecuteQuery() method which will actually send the query to the server. This is the advantage of Batching in JSOM.



Note: Chattier is another term that means the opposite of Batching. Chattier means it requires chat like request-response between client & server. So REST is chattier & JSOM not.

No comments:

Post a Comment

What is the cost of migration to SharePoint 2016?

Below are the points to understand better how much the cost of migration to SharePoint 2016 could be for your organization: What ver...