REST API in SharePoint 2010 for listdata.svc: Part 1


Introduction:

In SharePoint 2010, we can get the list data using SharePoint object model, client object model or LINQ to SharePoint, we can also get the list data from listdata.svc. We can get the list data from listdata.svc using REST (Representational State Transfer). We can construct URLs in various manners to get specific records, do joins, or perform simple queries. ListData.svc web service will be available in _vti_bin folder of the SharePoint site.

Get the data using REST API:

Typical URL to get the data from the SharePoint site using the REST API

http://<servername>/_vti_bin/listdata.svc.

I have a team site "VJTesting" which contains the "Tasks" list.

Tasks list has the following items as shown in the following.

RestApiShare1.gif

Try hitting the URL and you will be getting the XML file of the entire list available in the site.

RestApiShare2.gif

To get the specific item from the tasks list enter the following URL

http://<servername>/_vti_bin/listdata.svc/Tasks(2)/Title

RestApiShare3.gif

To get the specific item from the tasks list enter the following URL

http://<servername>/_vti_bin/listdata.svc/Tasks(2)/Title


RestApiShare4.gif

We can also use the filter the data from the list using $filter.

Filter - Restrict the entities returned from a query by applying the expression specified in this operator to the entity set identified by the last segment of the URI path.

For example

http://<servername>/_vti_bin/listdata.svc/Tasks?$filter=Title eq 'Task3'

RestApiShare5.gif

Top - This is used to restrict the maximum number of entities to be returned.

For example

http://<servername>/_vti_bin/listdata.svc/Tasks?$top=1

RestApiShare6.gif