SharePoint and Rest API - Introduction

What is SharePoint and REST?

SharePoint 2013 comes with a feature called REST i.e. REpresentational State Transfer; this helps developers to work on the data stored in SharePoint with much ease using any technology that supports RESTful services. Now developers can perform CRUD operations on the data sored in SharePoint using GET, PUT, POST and DELETE HTTP request.

How REST Operations are mapped with CRUD?

CRUD
HTTP Request
Comments
CREATE
POST
Use POST to create data in SharePoint.
READ
GET
Use GET to read data from SharePoint.
UPDATE
PUT/MERGE
Use PUT and MERGE to update the existing data in the SharePoint.
DELETE
DELETE
Use DELETE to delete data from SharePoint.

Mapping of SharePoint Client Object model API and REST API

Following data is collected from MSDN and this pretty much explains the mapping of client object model and REST endpoints.

Client object model API
REST endpoint
ClientContext.Web.Lists
http://server/site/_api/web/lists
ClientContext.Web.Lists[guid]
http://server/site/_api/web/lists(‘guid’)
ClientContext.Web.Lists.GetByTitle("Title")
http://server/site/_api/web/lists/getbytitle(‘Title’)

Querying SharePoint Data with REST

REST endpoint(http://server/site/)
Description(Support Operation)
_api/web/lists
Get all the lists from SharePoint Site.(GET)
_api/web/lists/getbytitle(‘Title’)
Get details of a list by its title.(GET,POST)
_api/web/lists(guid’guid of list’)
Get list details by its id, change in title will not affect your code.(GET,POST)
_api/web/lists/getbytitle(‘Title’)/Fields
Get all the fields in the list.(GET,POST)
_api/web/lists/getbytitle(‘Title’)/Fields/getbytitle(‘FTitle;)
Get a particular field detail and that detail can be manipulated (GET,PUT/MERGE.DELETE)
_api/web/lists/getbytitle(‘Title’)/Items
Get all the items in the list and support new items to be added(GET,POST)
_api/web/lists/getbytitle(‘Title’)/getitembyid(‘itemid’)
Get an item by its ID and supports new update an delete(GET,PUT/MERGE.DELETE)
Select Support
_api/web/lists/getbytitle(‘Title’)/Items$select=Title,Id
Select specific columns from the list; Title and Id in this case.(GET,POST)
Filter Support
_api/web/lists/getbytitle(‘Title’)/Items?$filter=ID eq 'id' or ID eq ‘id1’
Filter the data based on the ID.(GET,POST)
Order Support
_api/web/lists/getbytitle(‘Title’)/Items? &$orderby= ID asc
Order by ID asc order.(GET,POST)

Various Filtering Operations

As Per technet wiki following is the list of operations that can be used with the filter.

Supported
Not supported
Numeric comparisons
Lt
Le
Gt
Ge
Eq
Ne
Arithmetic operators 
(Add, Sub, Mul, Div, Mod)

Basic math functions 
(round, floor, ceiling)
String comparisons
startsWith
substringof
Eq
Ne
endsWith
replace
substring
tolower
toupper
trim
concat
Date and time functions
day()
month()
year()
hour()
minute()
second()
DateTimeRangesOverlap operator
Querying as to whether a date time falls inside a recurrent date time pattern


Comments

Popular posts from this blog

Azure - Manage Blob Storage - Part #7 - Add Metadata to an Existing Container using C#

Azure - Manage Blob Storage - Part #5 - Create Folder Structure and upload a file to folder using an Existing Container using C#

Algorithm - Breadth First Search(BFS) - Python(3)