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.
17. 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.
19. 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
20. 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
44. 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
46. 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' }
50. /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.