SharePoint 2013 RESTful service


SharePoint 2013 adds the ability for you to remotely interact with SharePoint sites by using REST. Now, you can interact directly with SharePoint objects by using any technology that supports standard REST capabilities.

To access SharePoint resources using REST, construct a RESTful HTTP request, using the Open Data Protocol (OData) standard, which corresponds to the desired client object model API. For example:

Below are some client object model methods.


The above method will get the SPWeb details of the Sales site.


The above method will displays all the list titles present in Sales web site.


The above url method displays employees' names from EmployeeList in Sales web site.

Getting the list data from SharePoint List using REST Services.

We can access the SharePoint content using both Server Side and Client Side code, in this example we are going to get the SharePoint List data using Client REST Calls.

REST calls mainly depending on the Service url, client.svc service will provide data based on the URL.

Below is the structure to generate the REST URL.
Steps to create REST Service

  1. Create Employee list and input some test data.


  2. Try to access the above URL to verify the service URL is returning proper data.


  3. Create site page and add below code to get the employee details.

    Add below code in main content section, we are trying to bind the employee information to eData ul on click of button.
    1. <input type="button" id="btnGetEmployees" value="Get Employees" />  
    2. <ul id="eData"></ul>  
    4. <script type="text/javascript">  
    5.     $(function()  
    6.     {  
    7.         $("#btnGetEmployees").click(function()  
    8.         {  
    9.             $.ajax(  
    10.                 {  
    11.                     url:"http://server17:1001/sales/_api/web/lists/getbytitle('EmployeeList')/items",  
    12.                     type: "GET",  
    13.                     contentType : "application/json",  
    14.                     headers : {"accept":"application/json;odata=verbose"},  
    15.                     success: OnSuccess,  
    16.                     error: OnError  
    17.                 }  
    18.             );  
    20.             // On success we are binding the result to UL  
    21.             function OnSuccess (result){  
    22.                 alert('Success!!!');  
    23.                 r = result.d.results;  
    24.                 for (var i =0; i<r.length; i++){  
    25.                     $("#eData").append ("<li>" + r[i].EmployeeName + "</li>");  
    26.                 }  
    27.             }  
    29.             // Alert the error message when error occurs  
    30.             function OnError (err){  
    31.                 alert ('Failed!!!');  
    32.             }  
    33.         });  
    34.     });  
    35. </script>  
    Here we are making AJAX call to get the Employee details using Service URL.


  4. Browse the created page and click on the Get Employees button, this will make REST call and bind the result to Unordered list.


Read more articles on SharePoint:

Up Next
    Ebook Download
    View all
    View all