REST API and                             Client Object                             Model for                             S...
Agenda Overview  of accessing Data in SharePoint Client Object Model    .NET Client Object Model    JavaScript and Cli...
First , How it was 2007 and whatwe have now in 2010 forAccessing Data in SharePoint
Accessing Data in 2007
Web Services Web services are available for use   _vit_bin/Lists.asmx   _vit_bin/Sites.asmx   _vit_bin/Webs.asmx   ….   …..
Why Client OM Disadvantages   of Web Services    Web Services can be complicated    Difficult to call from JavaScript ...
Accessing Data in 2010
Accessing data using REST
Integrating with SharePoint   Web Services       More coverage                                       Web Services       ...
How do I utilize client object model in my windows apps?.NET Client object model
Getting Started: 3 things to know1. ClientContext is the central object  clientContext =  new ClientContext(“http://mysite...
Client Application            Server     Sequence of              Client.svc     commands:     command 1;     command 2;  ...
Equivalent ObjectsServer       .NET Managed            Silverlight             JavaScript(Microsoft   (Microsoft.SharePoin...
.Net CLR Client OM Provides         easy access from remote .NET clients to manipulate SharePoint data Can be utilized f...
.NET Client OM Code Example 1ClientContext clictx = new ClientContext("http://intranet.contoso.com");        Site s1 = cli...
Client Object ModelClientContext ctx = new ClientContext(“http://mysite”);       Web web = ctx.Site.RootWeb;       ctx.Loa...
Uploading file example
Client Object ModelAuthentication      Uses Windows Authentication by default      Can be configured for Claims Based Auth...
Client Object Model Limitations You  still need to handle synch/update semantics  (change log could help) No elevation o...
21Demo
The JavaScript Client ObjectModel
Equivalent ObjectsServer       .NET Managed            Silverlight             JavaScript(Microsoft   (Microsoft.SharePoin...
JavaScript Client OM JavaScript           Client OM is easily added to a SharePoint  ASPX page - reference:     _layouts...
JavaScript Client OM C:Program   FilesCommon  FilesMicrosoft SharedWeb Server  Extensions14TEMPLATELAYOUTS SP.js (SP.deb...
JavaScript Client OM
27Java Script Client OM Demo
REST access to SharePoint dataREST & WCF Data Services
Why a RESTful Interface for SP? Why   REST    It is a natural fit for SharePoint data    Item == resource    Uniform i...
A RESTful Interface for Data Just   HTTP     Items as resources, HTTP methods (GET, PUT, …) to act     Leverage proxies...
Accessing data using REST
Operations Operations    map to HTTP verbs    Retrieve items/lists  GET    Create new item  POST    Update an item ...
URL ConventionsList of lists    …/_vti_bin/listdata.svc/List             listdata.svc/EmployeesItem          listdata.svc/...
34REST Demo
Summary Overview  of accessing Data in SharePoint Client Object Model    .NET Client Object Model    JavaScript and Cl...
Integrating with SharePoint   Web Services       More coverage                        Web Services                      ...
Accessing Data in 2010
Accessing data using REST
Rest API and Client OM for Developer
Rest API and Client OM for Developer
Upcoming SlideShare
Loading in...5
×

Rest API and Client OM for Developer

1,453

Published on

Presented at SharePoint TechFest on May 17, 2012. All rights reserved.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,453
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • ryadav@microsoft.com
  • http://msdn.microsoft.com/en-us/library/ee857094.aspxhttp://msdn.microsoft.com/en-us/library/hh185006
  • listdata.svc/Employees?$orderby=Fullnamelistdata.svc/Employees?$filter=JobTitleeq 'SDE'listdata.svc/Employees?$select=Fullname,JobTitlelistdata.svc/Employees?$top=10&$skip=30listdata.svc/Employees?$expand=Project
  • Rest API and Client OM for Developer

    1. 1. REST API and Client Object Model for SharePoint DeveloperRam YadavSr ConsultantMicrosoft Corp.MCM : SharePoint 2007/2010
    2. 2. Agenda Overview of accessing Data in SharePoint Client Object Model  .NET Client Object Model  JavaScript and Client Object Model REST & WCF Data Services
    3. 3. First , How it was 2007 and whatwe have now in 2010 forAccessing Data in SharePoint
    4. 4. Accessing Data in 2007
    5. 5. Web Services Web services are available for use _vit_bin/Lists.asmx _vit_bin/Sites.asmx _vit_bin/Webs.asmx …. …..
    6. 6. Why Client OM Disadvantages of Web Services  Web Services can be complicated  Difficult to call from JavaScript  Often custom wrapper services are created  Customers solve the same problem over and over again
    7. 7. Accessing Data in 2010
    8. 8. Accessing data using REST
    9. 9. Integrating with SharePoint Web Services  More coverage Web Services Advanced Operations SharePoint Server Client Object Model Operations  Site, navigation  security services Client OM Advanced List  Very flexible and straight forward Operations Site Operations REST Security  Easiest to use REST  For fixed list schema Working with list data, fixed schema RPC http://msdn.microsoft.com/en-us/library/ms478653.aspx Server Side code , List View , Data View
    10. 10. How do I utilize client object model in my windows apps?.NET Client object model
    11. 11. Getting Started: 3 things to know1. ClientContext is the central object clientContext = new ClientContext(“http://mysite”);2. Before you read a property, you have toask for it clientContext.Load(list);3. All requests must be committed in a batch clientContext.ExecuteQuery();
    12. 12. Client Application Server Sequence of Client.svc commands: command 1; command 2; Execute commands command 3; in the batch:context.ExecuteQuery(); command 1; command 2; command 3; Process results Send results back
    13. 13. Equivalent ObjectsServer .NET Managed Silverlight JavaScript(Microsoft (Microsoft.SharePoint (Microsoft.SharePoint (SP.js).SharePoint) .Client) .Client.Silverlight)SPContext ClientContext ClientContext ClientContextSPSite Site Site SiteSPWeb Web Web WebSPList List List ListSPListItem ListItem ListItem ListItemSPField Field Field FieldMember names mostly the same from server to client(e. g., SPWeb.QuickLaunchEnabled = Web.QuickLaunchEnabled)
    14. 14. .Net CLR Client OM Provides easy access from remote .NET clients to manipulate SharePoint data Can be utilized from managed code – also from office clients etc. Assemblies  Microsoft.SharePoint.Client.dll (281kb)  Microsoft.SharePoint.Client.Runtime.dll (145kb)  To Compare: Microsoft.SharePoint.dll – 15.3MB
    15. 15. .NET Client OM Code Example 1ClientContext clictx = new ClientContext("http://intranet.contoso.com"); Site s1 = clictx.Site; Web w1 = clictx.Site.RootWeb; clictx.Load(s1); clictx.Load(w1); clictx.ExecuteQuery(); var lists1 = clictx.LoadQuery(w1.Lists); clictx.ExecuteQuery(); var lists2 = clictx.LoadQuery(w1.Lists.Include(l => l.Title)); clictx.ExecuteQuery(); var query1 = from l1 in w1.Lists where l1.Title != null select l1; clictx.ExecuteQuery();
    16. 16. Client Object ModelClientContext ctx = new ClientContext(“http://mysite”); Web web = ctx.Site.RootWeb; ctx.Load(web); ctx.Load(web, w => w.Title, w => w.Description); ctx.Load(web, w => w.Title, w => w.Lists .Include(l => l.Fields .Include(f => f.InternalName, f => f.Group)));
    17. 17. Uploading file example
    18. 18. Client Object ModelAuthentication Uses Windows Authentication by default Can be configured for Claims Based Authenticationctx.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;ctx.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo("loginName", "password");
    19. 19. Client Object Model Limitations You still need to handle synch/update semantics (change log could help) No elevation of privilege capabilities Requests are throttled .net CLR has sync method; Silverlight CLR and Jscript are async
    20. 20. 21Demo
    21. 21. The JavaScript Client ObjectModel
    22. 22. Equivalent ObjectsServer .NET Managed Silverlight JavaScript(Microsoft (Microsoft.SharePoint (Microsoft.SharePoint (SP.js).SharePoint) .Client) .Client.Silverlight)SPContext ClientContext ClientContext ClientContextSPSite Site Site SiteSPWeb Web Web WebSPList List List ListSPListItem ListItem ListItem ListItemSPField Field Field FieldMember names mostly the same from server to client(e. g., SPWeb.QuickLaunchEnabled = Web.QuickLaunchEnabled)
    23. 23. JavaScript Client OM JavaScript Client OM is easily added to a SharePoint ASPX page - reference:  _layouts/sp.js  Add this using <SharePoint:ScriptLink> All libraries crunched for performance  Use un-crunched *.debug.js files with debug mode Method signatures can be different compared to .NET and Silverlight Different data value types
    24. 24. JavaScript Client OM C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATELAYOUTS SP.js (SP.debug.js)  380KB (559KB) SP.Core.js (SP.Core.debug.js)  13KB (20KB) SP.Runtime.js (SP.Runtime.debug.js)  68KB (108KB)
    25. 25. JavaScript Client OM
    26. 26. 27Java Script Client OM Demo
    27. 27. REST access to SharePoint dataREST & WCF Data Services
    28. 28. Why a RESTful Interface for SP? Why REST  It is a natural fit for SharePoint data  Item == resource  Uniform interface and addressing scheme  Low barrier of entry, interoperability Why WCF Data Services  RESTful conventions & frameworks for data  Builds on top of standard AtomPub  Exactly the sort of convention we needed  Consistent tools and client libraries
    29. 29. A RESTful Interface for Data Just HTTP  Items as resources, HTTP methods (GET, PUT, …) to act  Leverage proxies, authentication, ETags, … Uniform URL convention  Every piece of information is addressable  Predictable and flexible URL syntax Multiple representations  Use regular HTTP content-type negotiation  JSON and Atom (full AtomPub support)
    30. 30. Accessing data using REST
    31. 31. Operations Operations map to HTTP verbs  Retrieve items/lists  GET  Create new item  POST  Update an item  PUT or MERGE  Delete an item  DELETE  These apply to links (lookups) as well SharePoint rules apply during updates  Validation, access control, etc.
    32. 32. URL ConventionsList of lists …/_vti_bin/listdata.svc/List listdata.svc/EmployeesItem listdata.svc/Employees(123)  Addressing lists and itemsSingle column listdata.svc/Employees(123)/FullnameLookup listdata.svc/Employees(123)/ProjecttraversalRaw value listdata.svc/Employees(123)/Project/Title/$valueaccessSorting listdata.svc/Employees?$orderby=FullnameFiltering listdata.svc/Employees?$filter=JobTitle eq SDEProjection listdata.svc/Employees?$select=Fullname,JobTitlePaging listdata.svc/Employees?$top=10&$skip=30Inline expansion listdata.svc/Employees?$expand=Project
    33. 33. 34REST Demo
    34. 34. Summary Overview of accessing Data in SharePoint Client Object Model  .NET Client Object Model  JavaScript and Client Object Model REST & WCF Data Services
    35. 35. Integrating with SharePoint Web Services  More coverage Web Services Advanced Operations SharePoint Server Client Object Model Operations  Site, navigation  security services Client OM Advanced List  Very flexible and straight forward Operations Site Operations Security REST  Easiest to use REST Working with list  For fixed list schema data, fixed schema Server Side OM
    36. 36. Accessing Data in 2010
    37. 37. Accessing data using REST

    ×