Friday, June 20, 2014

An Introduction : REST in SharePoint 2013

SharePoint 2013 introduces a Representational State Transfer (REST) service.  You can interact remotely with SharePoint data by using any technology that supports REST web requests. You can now perform Create, Read, Update, and Delete (CRUD) operations for SharePointfrom remote application using REST web technologies and standard Open Data Protocol (OData) syntax. The remote application must be obtain autorized access. Check this MSDN article that covers Authorization and Authentication using ODATA. REST also used Client.svc to perform SharePoint Operations.

To use REST capabilities, you need contruct the HTTP request using OData standard.

If you want to do this to an endpoint
Use this HTTP request
Read a resource
GET
Create or update a resource
POST
Use POST to create entities such as lists and sites. The SharePoint 2013 REST service supports sending POSTcommands that include object definitions to endpoints that represent collections.
For POST operations, any properties that are not required are set to their default values. If you attempt to set a read-only property as part of a POST operation, the service returns an exception.
Update or insert a resource
PUT
Use PUT and MERGE operations to update existing SharePoint objects.
Any service endpoint that represents an object property set operation supports both PUT requests andMERGE requests.
·         For MERGE requests, setting properties is optional; any properties that you do not explicitly set retain their current property.
·         For PUT requests, if you do not specify all required properties in object updates, the REST service returns an exception. In addition, any optional properties you do not explicitly set are set to their default properties.
Delete a resource
DELETE
Use the HTTP DELETE command against the specific endpoint URL to delete the SharePoint object represented by that endpoint.
In the case of recyclable objects, such as lists, files, and list items, this results in a Recycle operation.

URI structure:


To access SharePoint resource, you must build the URI endpoint. Check the image for URI syntax





OData Query operators supported in SharePoint 2013:

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

The figure below shows the supported OData query options.

In The next few posts, I will perform some basic operation using REST api.

No comments:

Post a Comment