![Page 1: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/1.jpg)
Are You Getting Sleepy? REST with SharePoint AppsLiam Cleary
![Page 2: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/2.jpg)
About Me
• Solution Architect @ Protiviti
• 7 Time SharePoint MVP
• Cover Everything-SharePoint• Development
• Branding
• Design
• Architecture
• Security
• Dream about SharePoint, well sometimes
![Page 3: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/3.jpg)
Session Type
101
![Page 4: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/4.jpg)
Agenda
REST SharePoint 2013
SharePoint Apps
Thoughts
![Page 5: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/5.jpg)
REST
![Page 6: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/6.jpg)
What is REST, well SharePoint REST?
REST• Representational State
Transfer• Vocabulary Based• GET
• POST
• PUT
• PATCH
• DELETE
SharePoint REST• HTTP-Based Architecture• Uses Nouns and Verbs• Items, GET, POST, PUT, DELETE
• OData Provides the Description/Metadata• “/items(1)”
• CSOM is the Processor• Returns JSON or XML
• “/items/GetByTitle(‘Test’)”
![Page 7: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/7.jpg)
The REST Flow
Create
POST
Read
GET
Update/Delete
PUT
MERGE
DELETE
![Page 8: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/8.jpg)
REST Syntax
http://site/_api/web/lists/getbytitle('Shared Documents')/items/getbyid(1)?$select=Title,ID
LocationService Resource Path Query Options
![Page 9: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/9.jpg)
REST Filtering
Option Description
$expand Directs that related records should be retrieved in the record or collection being retrieved.
$filter Specifies an expression or function that must evaluate to ‘true’ for a record to be returned in the collection.
$orderby Determines what values are used to order a collection of records.
$select Specifies a sub set of properties to return.
$skip Sets the number of records to skip before it retrieves records in a collection.
$top Determines the maximum number of records to return.
![Page 10: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/10.jpg)
SharePoint 2013
![Page 11: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/11.jpg)
SharePoint 2013 REST Endpoints
Site
Webs
Features
Event Receiver
s
Web
Lists
Items
Publishing
Pages
Variations
Navigation
User Profiles
Users
Profiles
Activity
Search
Query Results
Suggestions
Taxonomy
Managed
Metadata
![Page 12: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/12.jpg)
SharePoint 2013 REST Security
Local
Current Context
Request Digest
Context Info
Remote
OAuth
Access Token
Cross Domain
Cross Domain
Request Executor
SP.WebProxy
HTTP WebRequest
![Page 13: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/13.jpg)
Endpoints – Example READ
URL Returns
_api/web/title “Title” of the current site
_api/web/lists(guid'<list id>') Get the list from supplied ID
_api/web/lists/getByTitle('Announcements')/fields
Get all columns from the “Announcements” list
_api/web/lists/getByTitle('Task')/items
Get items from the “Task” list
_api/web/siteusers Get users in the site
_api/web/sitegroups Get user groups in the site
_api/web/sitegroups(3)/users Get users that belong to group “3”
_api/web/GetFolderByServerRelativeUrl('/Shared Documents')
Get root folder of the Shared Documents library
_api/web/GetFolderByServerRelativeUrl('/Test')/Files('a.txt')/$value
Get “a.txt” from the “Test” document library
![Page 14: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/14.jpg)
SharePoint Apps
![Page 15: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/15.jpg)
SharePoint App Types
Provider Hosted
App Web - Optional
Dedicated Hosting
REST + OAuth
CSOM
Auto hosted
App Web – Optional
Windows/SQL Azure
REST + Oauth
CSOM
SharePoint Hosted
App Web
REST
JSOM
![Page 16: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/16.jpg)
SharePoint 2013 App User Experience
Immersive
Full Page
Redirect to App Web
Chrome will be needed
Part
Web/App Part
Page(s) Loaded from
App Web
Fit into existing
structure and chrome
Custom Actions
Ribbon
ECB
Redirect to App Web
Part of the native UI
![Page 17: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/17.jpg)
Code
![Page 18: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/18.jpg)
SharePoint 2013 REST - jQuery
jQuery.ajax({
url: “http://site url/_api/web/lists”,
type: “GET”,
headers: {
“ACCEPT”: “application/json;odata=verbose”,
“Authorization”: “Bearer “ + accessToken
},
})
![Page 19: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/19.jpg)
SharePoint 2013 REST – Cross Domain Library
var executor;
executor = new SP.RequestExecutor(appweburl);
executor.executeAsync(
{
url: appweburl + "/_api/SP.AppContextSite(@target)/web/Folders?@target='" + hostweburl + "'",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: getSuccessHandler,
error: getErrorHandler
}
![Page 20: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/20.jpg)
SharePoint 2013 REST – C#
HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create("http:// <site url>/_api/web/lists");
endpointRequest.Method = "GET";
endpointRequest.Accept = "application/json;odata=verbose";
endpointRequest.Headers.Add("Authorization", "Bearer " + accessToken);
HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
![Page 21: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/21.jpg)
Show Me The Money
![Page 22: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/22.jpg)
Thoughts
![Page 23: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/23.jpg)
Thoughts
Feature .NET Framework / Silverlightobject models
JavaScript object model REST / OData Endpoints
Object-oriented programming Yes Yes No
Batch processing Yes Yes No
APIs for conditional processing and exception handling
Yes No No
Availability of LINQ syntax Yes No No
Combining list data from different SharePoint web applications
Yes No Yes
Familiarity to experienced REST/OData developers
No No Yes
Similarity to non-Windows programming or JavaScript programming
No Yes Yes
Strong typing for list item fields
No (except with LINQ) No Yes, from Windows platformNo, from JavaScript
Leveraging jQuery, Knockout, and other JavaScript libraries
No Yes No, from Windows platformYes, from JavaScript
![Page 24: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/24.jpg)
Thoughts
• Data is returned as XML in AtomPub• Extended by the OData Format – “accept:
application/json;odata=verbose”
• OData and SharePoint REST are not the same
• Choose the right data retrieval
• Set the correct permissions for your SharePoint App
![Page 25: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/25.jpg)
Resources
• http://www.mavention.nl/blog/configuring-sharepoint-2013-search-rest-api-anonymous-users
• http://msdn.microsoft.com/en-us/library/jj164022.aspx
• http://msdn.microsoft.com/en-us/magazine/dn198245.aspx
• http://msdn.microsoft.com/en-us/library/dn292553.aspx
• http://msdn.microsoft.com/en-us/library/dn292552.aspx
• http://msdn.microsoft.com/en-us/library/fp142380.aspx
![Page 26: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/26.jpg)
Resources
• Please remember to turn in your filled out bingo cards and event evaluations for prizes.
• SharePint is sponsored by Slalom at Whiskey Trader (Between 55th and 56th on 6th Avenue).
• Follow SharePoint Saturday New York City on Twitter @spsnyc and hashtag #spsnyc
![Page 27: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/27.jpg)
Thank You to the Sponsors
![Page 28: Are you getting Sleepy. REST in SharePoint Apps](https://reader033.vdocuments.us/reader033/viewer/2022061110/5453f4aeaf79597c338b4a25/html5/thumbnails/28.jpg)
Thank You