This document discusses building a mobile social voting app called "Hot or Not" using the SharePoint REST API. It begins with an overview of mobile social apps and the demo app. It then summarizes how the app is built as a SharePoint-hosted app using JavaScript, the REST API, and remote event receivers. The document demonstrates basic REST operations and discusses various REST endpoints. It also covers using the REST API in JavaScript and issues like the form digest. Finally, it discusses using remote event receivers for push notifications and the Windows Phone 8 client SDK.
3. About me • Joris.Poelmans@gmail.com
• Principal consultant at RealDolmen
• SharePoint Server MVP since 2005
• http://jopx.blogspot.com
• Twitter: @jopxtwits
• Founding member of BIWUG
4. About this
session
• Not really about standard social
features in SharePoint
• Focus on building a (voting) app
• ... All with REST API
7. Dissecting
HotOrNot
• SharePoint Hosted app
(Almost) completely build in Javascript
Uses JSRender, JQuery UI, Image-picker
Uses REST API to communicate with
SharePoint
Remote Event Receivers (RER) for mobile
notifications (work in progress)
Consumed by Windows Phone 8 application
(work in progress)
8. About Apps • Apps are self-contained pieces of
functionality that extend the capabilities of
a SharePoint site which leverage web
technologies
New deployment method
Low server footprint
Cloud driven
Using an app catalog
9. App Web
Parent
Web
SharePoint-hosted App
Provision an isolated sub web on
a parent web
• Reuse web elements
(lists, files, out-of-box web
parts)
• No server code allowed;
use client JavaScript for
logic, UX
Azure Auto-
Provisioned App
Windows Azure + SQL Azure
provisioned invisibly as apps
are installed
AzureSharePoint
Web
Get remote events
from SharePoint
Use CSOM/REST +
OAuth to work
with SPS
Cloud-based
Apps
Developer-Hosted App
“Bring your own server hosting
infrastructure”
Developers will need to isolate
tenants
SharePoint
Web
Your Hosted
Site
10. Cloud hosted
versus
SharePoint
hosted
Cloud Hosted Apps SharePoint Hosted Apps
Preferred hosting model for almost
all types of apps
Good for smaller apps & resource
storage
Full power of web – choose your
infrastructure & technology
SharePoint-based; no server-side
code
May require your own hosting Automatically hosted in
SharePoint
May require you own handling of
multitenancy & permission
management
Inherent multitenancy & isolation
11. Background
on REST API
HTTP-based web service architecture that uses
nouns and verbs to define operations
Noun: “Items”
Verbs: GET, POST, PUT, MERGE, DELETE
oData provides metadata, object typing and query
semantics
/items(0)
Client Object Model service (client.svc) processes
queries, interacts with server OM and returns
JSON/XML
/items/GetByTitle(„foo‟)
13. Things to
watch out for
• oData Spec != SharePoint REST
• No request batching
• Must specify “odata=verbose” in header
• Default response format is ATOM but JSON is
easier with Javascript
• Some request may not return default values (due
to processing overhead)
• Lots of different REST endpoints available
15. Javascript
and REST API
• Async GET/POST operations using AJAX library
• Alternative cross-domain library
• SP.RequestExecutor
• Must specify “odata=verbose” in header
• Change default response format is to JSON
• Accept: “application/json;odata=verbose”
• Lots of different REST endpoints available
16. Form Digest • Updates using REST require Form Digest
• Prevent replay attacks
• SharePoint pages have a control holding a
Form Digest
• Updates/Deletes will fail without digest value
• Local app pages
• Use $(“#__REQUESTDIGEST”).val()
• Remote
• POST to /_api/contextinfo to obtain form
digest
18. CRUD
Operations
(Read)
• Read List Item
• Use jsRender library which provides template
based rendering
• Use $.template to create a template
• Use $.render to generate output from JSON
collection
23. Search REST
API
• Not a lot of documentation available
• See -
http://blogs.msdn.com/b/nadeemis/archive/2012/08/24/sharepoint-
2013-search-rest-api.aspx
• Search REST App -
http://sharepointfieldnotes.blogspot.be/2013/01/sharepoint-2013-
search-with-rest-app.html
• Use Codeplex Search Tool -
http://sp2013searchtool.codeplex.com/
24. Must have
tool
• Use SPFastDeploy to deploy individual items
without having to do a full deploy
• Download link:
http://visualstudiogallery.msdn.microsoft.com/9e03
d0f5-f931-4125-a5d1-7c1529554fbd
26. Remote Event
Receivers
(1/2)
• Provides a way to notify external systems
• Support synchronous and asynchronous events
• Similar to “normal” event receivers but containers
pointer to WCF service
28. Mobile Push
Notifications
Walkthrough
• See How to: Create a companion mobile app for
an app for SharePoint -
http://msdn.microsoft.com/en-
us/library/jj923094.aspx
• Step 1: Create a list-based autohosted app in
SharePoint 2013
• Step 2: Configure push notifications in
autohosted app
• Step 3: Create a mobile app and register for
push notifications
29. Windows
Phone 8
Client
• New SharePoint SDK for WP8 available
http://www.microsoft.com/en-
us/download/details.aspx?id=36818
• 2 new templates (only C#):
• WP Empty SharePoint Application template
• WP SharePoint List Application template
• Specific references for interacting with SharePoint
• Microsoft.SharePoint.Client.Phone
• Microsoft.SharePoint.Client.Phone.Auth.UI
• Microsoft.SharePoint.Client.Phone.Runtime
• WP8 List Application template uses a wizard to
generate most of the code files
31. Conclusion • REST != CSOM, CSOM preferred option for
development in most use cases
• Probably use REST for
• Prototyping
• CRUD operations from LAMP /IOS/Android
platforms
• Possible option for WP8 or W8 apps
• Mobile companions to SharePoint apps make
sense
32. Call to Action • Help improve the Hot Or Not App – contact
@jopxtwits
• Improvements
• Allow to specify a challenge in the app part
• Include image when adding to the social feed
• Build a Windows 8 app, iOS and/or Android
app
• Add business logic
• Provide statistics and graphs
33. References
• Manipulating list items in SharePoint Hosted Apps using the
REST API -
http://blogs.msdn.com/b/uksharepoint/archive/2013/02/22/mani
pulating-list-items-in-sharepoint-hosted-apps-using-the-rest-
api.aspx
• How to: Learn to read and write to the social feed by using the
REST service in SharePoint 2013 -
http://msdn.microsoft.com/en-us/library/jj822974.aspx
• Debugging Remote Event Receivers with VS and Windows
Azure Service Bus -
http://blogs.msdn.com/b/officeapps/archive/2013/01/03/debuggi
ng-remote-event-receivers-with-visual-studio.aspx
34. Big thanks to • @ludwigvangysel for solving bugs and
troubleshooting
• @spsteve (Steve Curran) for creating
SPFastDeploy 2.2