Logo
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
PREGNANCY
 
 
Windows Server

Sharepoint 2013 : Overview of The Client-Side Object Model and Rest APIs - REST and OData (part 1) - Getting Started with REST and OData

8/17/2014 9:27:03 PM

REpresentational State Transfer (REST) is a prevalent pattern for designing easily consumed data APIs over the Internet. You might hear an API described as RESTful if it is designed to be used over HTTP protocols and is in line with the principles of REST. These principles are as follows:

  • Client-Server: The client is unaware of how the server stores or manages the data and doesn’t need to know in order to use the API.
  • Stateless: The server does not store any context or state about the calling client.
  • Cacheable: The results of the calls to the API define themselves as being cacheable, or not.
  • Layered: The client does not mind whether the call to the API is transmitted via common Internet technology such as load balancers.
  • Uniform Interface: This provides a simple and known way to access data through standard URI addressing and self-describing so that a client can discover how to access data.

Many services offer REST-based APIs to ease access to their systems in a commonly understood manner. SharePoint 2013 builds on this foundation to offer access in a “RESTful” way to allow remote systems to interact with it in a platform agnostic and open way. For developers this means that using other helper libraries and frameworks for working with REST is a viable method, and the time to become proficient in a proprietary API is decreased.

OData or Open Data Protocol is a protocol definition for querying, finding, and updating data over HTTP. It offers defined methods for specifying common query operations and defines the format in which data is returned. SharePoint 2013 uses WCF Data Services v5.0 which implements the OData v3 specification. For more information on OData you can visit: http://www.odata.org.

Combining a RESTful Web API with OData gives a powerful combination of simple and easy-to-use APIs that have a well-defined interface and interaction model. In practical terms, having access to a RESTful OData-based API means the following for SharePoint developers:

  • Standard URIs for addressing data
  • Simple use of GET, POST, PUT/MERGE, and DELETE HTTP methods
  • JSON or XML (ATOM) responses
  • Simple query/filter semantics

The following sections describe each of the preceding points with simple-to-follow examples of how they are addressed in SharePoint 2013’s implementation of its REST/OData Web API endpoints.

Getting Started with REST and OData

You can find SharePoint’s REST/OData APIs in the _API URL space under each SharePoint site. For example:

https://servername/sitename/_api/

_api is the root URI for all REST/OData calls. SharePoint also supports calls to the _vti_bin/client.svc/ URI to maintain backward compatibility with the previously available but more limited REST API in SharePoint 2010.

To query for data, issue a GET request. To update data you use either a PUT or MERGE request passing the data you want to update. But first you must specify which namespace it belongs in, such as Web, Site, or Search. Other groups include:

  • _api/web
  • _api/site
  • _api/search
  • _api/publishing

After you specify a namespace you must address an object, method, indexer, or property on it. Figure 1 depicts the URI address system.

FIGURE 1

image

To retrieve the list of lists on a SharePoint site simply issue a GET request to the following:

https://servername/sitename/_api/web/lists

To retrieve the details about a list simply make a GET request to that list’s URI indicated in the previous response’s id property. For example:

https://servername/sitename/_api/Web/Lists(guid'f57d3ddc-4522-4145-a0fe-72abbd6ea8fc')

This example uses the Lists method with a parameter to specify the ID of the list. You could also use the list’s entity name; for example:

https://servername/sitename/_api/Web/Lists/MoviesList

Additionally, you can address a list by name using the getbytitle function as follows. This addresses the list with its name versus its entity name:

https://servername/sitename/_api/Web/Lists/getbytitle('movies')/items

To access the items within a list add /items to the URI:

https://servername/sitename/_api/Web/Lists/MoviesList/Items

By default you will receive an ATOM feed XML response containing the lists in your site. If you want to receive a JSON payload instead, set the HTTP Accept header to application/json;odata=verbose. This signals that you want JSON instead of the default ATOM payload. JSON is typically lighter weight and better suited to mobile scenarios where speed is important.

Other -----------------
- Sharepoint 2013 : Integrating Apps for Office with SharePoint (part 2) - Apps for Office Integrated with an App for SharePoint
- Sharepoint 2013 : Integrating Apps for Office with SharePoint (part 1) - Standalone Apps for Office
- Sharepoint 2013 : The Office JavaScript Object Model (part 3) - App Security
- Sharepoint 2013 : The Office JavaScript Object Model (part 2) - Functional Capabilities by Office Client,Mailbox-based Apps
- Sharepoint 2013 : The Office JavaScript Object Model (part 1) - Document-based Apps
- SQL Server 2012 : Understanding Latches and Spinlocks (part 3) - Latching Example - With Latching
- SQL Server 2012 : Understanding Latches and Spinlocks (part 2) - Latching Example - Without Latching
- SQL Server 2012 : Understanding Latches and Spinlocks (part 1) - Latching Example
- SQL Server 2012 : Latches and Spinlocks - Symptoms (part 2) - Measuring Latch Contention, Measuring Spinlock Contention , Contention Indicators
- SQL Server 2012 : Latches and Spinlocks - Symptoms (part 1) - Recognizing Symptoms
- Integrating SharePoint 2013 with the Office Applications (part 10) - Microsoft Outlook - Lists and Libraries
- Integrating SharePoint 2013 with the Office Applications (part 9) - Microsoft InfoPath - Customizing the Document Information Panel and List Forms
- Integrating SharePoint 2013 with the Office Applications (part 8) - Microsoft InfoPath -Deploying a Form Via Central Administration, Rendering a Form Using the InfoPath Form Web Part
- Integrating SharePoint 2013 with the Office Applications (part 7) - Microsoft Access - Access Services
- Integrating SharePoint 2013 with the Office Applications (part 6) - Microsoft Access
- Integrating SharePoint 2013 with the Office Applications (part 5) - Microsoft OneNote
- Integrating SharePoint 2013 with the Office Applications (part 3) - Microsoft Excel
- Integrating SharePoint 2013 with the Office Applications (part 3) - Microsoft Excel
- Integrating SharePoint 2013 with the Office Applications (part 2) - Microsoft Word - Compare Document Versions, Quick Parts
- Integrating SharePoint 2013 with the Office Applications (part 1) - Microsoft Word - Writing Blog Posts
 
 
Most view of day
- Programming Drivers for the User Mode Driver Framework - Driver Dynamic-Link Library and Exports
- Mix and Match with Old Windows and Macs : Internetworking with Windows 95, 98, and Me, Internetworking with UNIX and Linux
- Microsoft Exchange Server 2010 : Defining Email Addresses (part 2) - Email Address Policies - Changing an Existing Policy
- Microsoft Project 2010 : Setting Up a Project Budget - Assigning Accounting Codes
- Working with the User State Migration Tool (part 3) - Gathering Data by Running ScanState
- Deploying the Client for Microsoft Exchange Server 2007 : Planning Considerations and Best Practices, Preparing the Deployment
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Setting ActiveX Security Options
- Managing SharePoint 2010 with Windows PowerShell : Managing SharePoint 2010 Web Applications
- Sharepoint 2013 : The Office JavaScript Object Model (part 1) - Document-based Apps
- Microsoft Systems Management Server 2003 : Analysis and Troubleshooting Tools - Using SMS Service Manager
Top 10
- Windows Server 2012 : Administering Active Directory using Windows PowerShell (part 3) - Performing an advanced Active Directory administration task
- Windows Server 2012 : Administering Active Directory using Windows PowerShell (part 2) - Finding Active Directory administration cmdlets
- Windows Server 2012 : Administering Active Directory using Windows PowerShell (part 1) - Managing user accounts with Windows PowerShell
- Windows Server 2012 : Enabling advanced features using ADAC (part 3) - Creating fine-grained password policies
- Windows Server 2012 : Enabling advanced features using ADAC (part 2) - Configuring fine-grained password policies
- Windows Server 2012 : Enabling advanced features using ADAC (part 1) - Enabling and using the Active Directory Recycle Bin
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Marking a Workbook as Read-Only
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Working with Office Safe Modes
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Setting External Content Security Options
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Setting Privacy Options - Set Parental Controls for Online Research
 
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro