Hard learned CSOM and REST tips
Upcoming SlideShare
Loading in...5
×
 

Hard learned CSOM and REST tips

on

  • 1,509 views

CSOM and REST should probably be #1 on your list of things to learn. You’ve probably seen those tutorials, copy pasted code, the basic hello world apps. Well life is a lot different when writing a ...

CSOM and REST should probably be #1 on your list of things to learn. You’ve probably seen those tutorials, copy pasted code, the basic hello world apps. Well life is a lot different when writing a relatively complex app. How do you do error handling, concurrency checks, thread synchronization, memory tracking and optimization, and browser independence while taking advantage of newer browsers. Let’s not forget the pain writing and debugging your JavaScript can be, unless of course you structure it right. But how is a developer to match all those parenthesis and semicolons, or check for variable types where your best dev. environment is F12? This session is a hands-on dive into such fun topics.

Statistics

Views

Total Views
1,509
Slideshare-icon Views on SlideShare
1,506
Embed Views
3

Actions

Likes
1
Downloads
33
Comments
0

1 Embed 3

https://twitter.com 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Hard learned CSOM and REST tips Hard learned CSOM and REST tips Presentation Transcript

    • Hard learned CSOM and REST SAHIL MALIK WWW.WINSMARTS.COM @SAHILMALIK SHAREPOINT AND PROJECT CONFERENCE ADRIATICS 2013 ZAGREB, NOVEMBER 27-28 2013
    • sponsors
    • C:>whoami 11xMVP 15xAuthor Pluralsight Author Microsoft Metro Trainer Funny and Honest HTTP://BLAH.WINSMARTS.COM @SAHILMALIK
    • Hard learned SharePoint dev tips 0945AM Hard learned CSOM and REST 0345PM
    • Client side technologies in SharePoint 2013
    • Why Microsoft created REST and CSOM?
    • Why Microsoft created REST and CSOM
    • Why do you need to learn about REST and CSOM? * There are some minor differences in the REST/CSOM API in Office 365
    • Synchronous vs. Asynchronous var data = DownloadData(...); ProcessData(data); DownloadDataAsync(... , data => { ProcessData(data); });
    • Synchronous vs. Asynchronous var data = DownloadData(...); ProcessData(data); DownloadDataAsync(... , data => { ProcessData(data); });
    • Asynch Code challenges – Error Handling DownloadDataAsync(... , data => { ProcessData(data); });
    • Asynch Code Challenges – Timing issues
    • Asynch Code Challenges - Concurrency
    • Async code challenges
    • Concurrency, so how does it work?
    • The general theme
    • CSOM/REST comparison What CSOM REST Going to the server ExecuteQuery ExecuteQueryAsync $.get $.getJSON $.ajax Concurrency Checks built into framework during save operations. Object Identity & Object Tracking eTAG support Data Objects Objects that inherit from ClientObject JavaScript objects, or similar non-intelligent business objects Usual application Usually C# etc. (server side code in apps) Usually browser side code (usually JavaScript) Security Piggy backs on transport security + OAuth Piggy backs on browser security + OAuth Community support SharePoint specific – some support. JavaScript and jQuery and REST are open standards – lots of support.
    • CSOM
    • How CSOM works Create a ClientContext Use Load/LoadQuery to specify what data you wish to get Get data using ExecuteQuery/ExecuteQueryAsync Make changes to data Save data using ExecuteQuery/ExecuteQueryAsync
    • How CSOM works Client Application Server Sequence of commands: Client.svc command 1; command 2; command 3; context.ExecuteQuery(); Process results XML JSON Execute commands in the batch: command 1; command 2; command 3; Send results back
    • ClientContext
    • Client Objects Server (Microsoft .SharePoint) .NET Managed (Microsoft.SharePoint .Client) Silverlight (Microsoft.SharePoint .Client.Silverlight) JavaScript (SP.js) SPContext ClientContext ClientContext ClientContext SPSite SPSite SPSite Site SPWeb SPWeb SPWeb Web SPList SPList SPList List SPListItem SPListItem SPListItem ListItem SPField SPField SPField Field SPWeb.Title SPWeb.Title SPWeb.Title web.get_Title(); web.set_Title(); Member names mostly the same from server to client (e. g., SPWeb.QuickLaunchEnabled = SPWeb.QuickLaunchEnabled) JavaScript frequently has get_ set_ methods instead of properties
    • Load vs LoadQuery
    • Update Data
    • ExecuteQuery vs ExecuteQueryAsync
    • Upload file using CSOM
    • How to use CSOM? – Silverlight http://blah.winsmarts.com/2010-3-Integrating_Silverlight_BING_Maps_with_SharePoint_2010.aspx
    • How to use CSOM? – Windows Phone
    • How to use CSOM? – JavaScript
    • Referencing CSOM by hand
    • Get and Set Web properties
    • Get List Items
    • Method Chaining
    • CRUD Operations
    • REST API
    • What is REST?
    • REST Data Formats
    • REST API
    • SharePoint 2013 REST URL structure http://server/site/_api/site
    • SharePoint REST API Parameter structure http://server/site/_api/web/getAvailableWebTemplates(lcid=1033, includeCrossLanguage=true)
    • SharePoint REST service parameter aliasing syntax http://server/site/_api/userProfiles/People(7)/GetWorkplace(@address)?@address={"__metadata":{"type: "ODataDemo.Address"},"Street":"NE 228th", "City":"Sammamish","State":"WA","ZipCode":"98074","Country": "USA"}
    • REST service syntax for parameters in query string http://<server>/<site>/_api/web/applyWebTemplate?template=”STS#0”
    • Query Operator Support
    • REST Query Operators Supported Numeric comparisons •Lt •Le •Gt •Ge •Eq •Ne String comparisons •startsWith •substringof •Eq •Ne Date and time functions •day() •month() •year() •hour() •minute() •second() Not supported •Arithmetic operators (Add, Sub, Mul, Div, Mod) •Basic math functions (round, floor, ceiling) •endsWith •replace •substring •tolower •toupper •trim •concat •DateTimeRangesOverlap operator •Querying as to whether a date time falls inside a recurrent date time pa
    • Example
    • Example Queries Description URL endpoint HTTP method Body content Retrieves the title of a list web/title GET Not applicable Retrieves all lists on a site lists GET Not applicable Retrieves a single 'list's metadata lists/getbytitle('listname') GET Not applicable Retrieves items within a list lists/getbytitle('listname')/items GET Not applicable Retrieves a specific property of a document. (In this case, the document title.) lists/getbytitle('listname')?select=Ti tle GET Not applicable Creates a list lists POST { '_metadata':{'type':SP.List}, 'AllowContentTypes': true, 'BaseTemplate': 104, 'ContentTypesEnabled': true, 'Description': 'My list description', 'Title': 'RestTest' } Adds an item to a list lists/getbytitle('listname')/items POST { '_metadata':{'type':SP. listnameListItem}, 'Title': 'MyItem' }
    • HTTP Methods
    • HTTP Methods
    • Form Digest
    • /contextinfo Property Description webFullUrl Gets the server-relative URL of the nearest site. siteFullUrl Gets the server-relative URL of the root of the site collection that the site is contained within. If the nearest web is the root of a site collection, then the value of the webFullUrl property is equal to the siteFullUrl property. formDigestValue Gets the server's request form digest. LibraryVersion Gets the current version of the REST library. SupportedSchemaVersions Gets the versions of the schema of the REST/CSOM library that are supported.
    • Traversing Folders
    • CRUD Operations
    • Create a site
    • Create a list
    • Create a file in a doc lib Create a file in a folder
    • Update – Either PUT or PATCH(MERGE)
    • Update using PUT
    • Update using PATCH
    • Getting contents of a file
    • Deletes
    • ETags
    • Get Changes since last refresh
    • REST Error Diagnosis
    • questions? HTTP://BLAH.WINSMARTS.COM @SAHILMALIK
    • thank you. SHAREPOINT AND PROJECT CONFERENCE ADRIATICS 2013 ZAGREB, NOVEMBER 27-28 2013