_api: the evolution of the client object model and rest api for sharepoint 2013

17
_api: : The evolution of the Client Object Model and REST API for SharePoint 2013 Rob Windsor [email protected] @robwindsor

Upload: rob-windsor

Post on 01-Nov-2014

1.907 views

Category:

Technology


0 download

DESCRIPTION

When building SharePoint 2013 Apps, developers are restricted from using the SharePoint Server Object Model. To enable you to build fully-featured solutions using the App model, Microsoft has greatly enhanced and extended the Client Object Model and REST API. This session begins with a brief introduction to the 2010 versions of these APIs and then explores how they have evolved and how to use them effectively when building SharePoint 2013 Apps or Solutions.

TRANSCRIPT

Page 1: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

_api: : The evolution of

the Client Object Model

and REST API for

SharePoint 2013

Rob Windsor

[email protected]

@robwindsor

Page 2: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

About Me

• Senior SharePoint Architect with Portal Solutions

• Technical Contributor to the Pluralsight On-Demand Library

• Microsoft MVP, MCPD, MCT

• Founder and Past-President of the North Toronto .NET UG

• Co-author of Prof. Visual Basic 2012 and .NET 4.5 (Wrox)

Page 3: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

Client(-Side) Object Model (CSOM)

• API used when building remote applications

Introduced in SharePoint 2010

Designed to be similar to the Server Object Model

• Three implementations

.NET Managed, Silverlight, JavaScript

Façades on top of /_vti_bin/Client.svc

• Communication with SharePoint done in batches

Page 4: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

What’s New in SharePoint 2013

• Core API hasn’t changed much since 2010

• Greatly expanded coverage area

Sites, Webs, Features, Event Receivers, Site Collections

Lists, List Items, Fields, Content Types, Views, Forms

Files, Folders

Users, Roles, Groups, User Profiles, Feeds

Web Parts

Search

Taxonomy

Workflow

IRM

E-Discovery

Analytics

Business Data

Page 5: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

REST API

• Another API used when building remote applications

• What is the REST API in SharePoint

Data-centric web services based on the Open Data Protocol (OData) Does not completely conform to OData spec

Lack of metadata is one glaring example

Each resource or set of resources is addressable

http://<site url>/_api/web

http://<site url>/_api/web/lists

http://<site url>/_api/web/lists/getByTitle(‘Customers’)

Operations on resources map to HTTP Verbs

GET, PUT, POST, DELETE, …

Results from service returned in AtomPub (XML) or JavaScript Object

Notation (JSON) format

No batching of requests

Page 6: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

What’s New in SharePoint 2013

• ListData.svc deprecated

Still available for backwards compatibility

• RESTful operations added to /_vti_bin/Client.svc

/_api added as an alias for /_vti_bin/Client.svc

• Coverage area

Sites, Webs, Features, Event Receivers, Site Collections

Lists, List Items, Fields, Content Types, Views, Forms, IRM

Files, Folders

Users, Roles, Groups, User Profiles, Feeds

Search

Page 7: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

Reading Data

• Client Object Model

Load and LoadQuery allow you to specify desired

fields/properties

Can nest includes to eager load child collections

• REST API

Use OData query syntax

Check for continuations

Page 8: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

Creating Lists

• Client Object Model

ListCreationInformation

• REST API

POST

Body includes SP.List

Header includes Form Digest (X-RequestDigest)

SharePoint pages include Form Digest in hidden field

Page 9: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

Creating List Items

• Client Object Model

ListItemCreationInformation

• REST API

POST

Body includes SP.Data.<List Name>ListItem

Header includes Form Digest (X-RequestDigest)

SharePoint pages include Form Digest in hidden field

Page 10: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

Updating List Items

• Client Object Model

Same as server object model

• REST API

POST

Body includes SP.Data.<List Name>ListItem

Header includes Form Digest (X-RequestDigest)

SharePoint pages include Form Digest in hidden field

Header includes Request Method (X-Http-Method)

Set to PATCH or MERGE

Header includes concurrency option (IF-MATCH)

Set to item etag or *

Page 11: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

Creating Custom Fields

• Client Object Model

Fields.AddFieldAsXml

Prototype field first to have SharePoint generate schema

XML for you

• REST API

POST

Body includes SP.Field<Field Type>

Header includes Form Digest (X-RequestDigest)

SharePoint pages include Form Digest in hidden field

Page 12: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

Uploading Documents

• Client Object Model

FileCreationInformation

JavaScript

Use HTML5 FileReader to read

Use Uint8Array and SP.Base64EncodedByteArray to encode

• REST API

POST

Body contains document contents

Header includes Form Digest (X-RequestDigest)

SharePoint pages include Form Digest in hidden field

Header contains content length (Content-Length)

Page 13: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

User Profiles

• Client Object Model

PeopleManager

Microsoft.SharePoint.Client.UserProfiles

SP.UserProfiles.js

• REST API

GET

_api/SP.UserProfiles.PeopleManager

• Apps

Requires Read permission on User Profiles

Page 14: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

Search

• Client Object Model

KeywordQuery and SearchExecutor

Microsoft.SharePoint.Client.Search

SP.Search.js

• REST API

GET

_api/search

• Apps QueryAsUserIgnoreAppPrincipal

Page 15: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

Calling to Host Web

• Client Object Model

Use SP.AppContextSite to get host web context

Get SPHostUrl parameter from query string

• REST API

Use _api/SP.AppContextSite(@target) to get host web

context

Get SPHostUrl parameter from query string

Use SP.RequestExecutor to make call

Page 16: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

Web Proxy

• Client Object Model

SP.WebRequestInfo

SP.WebProxy.invoke

• REST API

POST

_api/SP.WebProxy.invoke

Body contains SP.WebRequestInfo

Page 17: _api: The evolution of the Client Object Model and REST API for SharePoint 2013

Thank You

• Big thanks to the organizers, sponsors and you for making

this event possible

• Please fill out your evaluation

• Please keep in touch

[email protected]

@robwindsor

msmvps.com/blogs/windsor