Consume SharePoint Online REST service using .NET

Overview

Since the introduction of REST interface in SharePoint 2010 you have probably used WebClient or HttpWebRequest in .NET applications.
HttpClient is a modern HTTP client for .NET, it provides a flexible and extensible API for accessing resources via HTTP(S).
HttpClient offers some advantages over WebClient/HttpWebRequest such as:

  1. An HttpClient instance is the place to configure extensions, set default headers, cancel outstanding requests and more.
  2. You can issue as many requests as you like through a single HttpClient instance.
  3. HttpClients are not tied to particular HTTP server or host; you can submit any HTTP request using the same HttpClient instance.
  4. You can derive from HttpClient to create specialized clients for particular sites or patterns
  5. HttpClient uses the new Task-oriented pattern for handling asynchronous requests making it dramatically easier to manage and coordinate multiple outstanding requests.

HttpClient for SharePoint Online

The solution consists of:

  1. SPHttpClient class that inherits from HttpClient and provides some additional SharePoint specific functionaly such as getting request digest
  2. SPHttpClientHandler class that basically hides all the intricacies related to SharePoint Online authentication

SharePoint Online client implementation

SharePoint Online HTTP handler implementation

Working with list items with REST

The following example shows how to retrieve all of a list’s items:

The following example shows how to retrieve a specific list item:

The following example shows how to create a list item:

The following example shows how to update a list item:

The following example shows how to delete a list item:

Advertisements

5 thoughts on “Consume SharePoint Online REST service using .NET

  1. Pingback: SharePoint 2013 & Office 365: Recopilatorio de enlaces interesantes (LXV)! - Blog de Juan Carlos González en Geeks.MS

  2. Pingback: Getting the list item Permission using Rest Api | DL-UAT

  3. Pingback: Sharepoint 2013 – Site Title

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s