Are you getting Sleepy. REST in SharePoint Apps


Published on

Published in: Technology
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Are you getting Sleepy. REST in SharePoint Apps

  1. 1. Are You Getting Sleepy? REST with SharePoint Apps Liam Cleary
  2. 2. About Me • Solution Architect @ Protiviti • 7 Time SharePoint MVP • Cover Everything-SharePoint • Development • Branding • Design • Architecture • Security • Dream about SharePoint, well sometimes
  3. 3. Session Type
  4. 4. Agenda REST SharePoin t 2013 SharePoin t Apps Thoughts
  5. 5. REST
  6. 6. 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‟)”
  7. 7. The REST Flow Create POST Read GET Update/Delet e PUT MERGE DELETE
  8. 8. REST Syntax http://site/_api/web/lists/getbytitle('Shared Documents')/items/getbyid(1)?$select=Title,ID Location Service Resource Path Query Options
  9. 9. 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.
  10. 10. SharePoint 2013
  11. 11. SharePoint 2013 REST Endpoints Site Webs Features Event Receivers Web Lists Items Publishin g Pages Variations Navigation User Profiles Users Profiles Activity Search Query Results Suggestio ns Taxonom y Managed Metadata
  12. 12. 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
  13. 13. 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('/S hared Documents') Get root folder of the Shared Documents library _api/web/GetFolderByServerRelativeUrl('/T est')/Files('a.txt')/$value Get “a.txt” from the “Test” document library
  14. 14. SharePoint Apps
  15. 15. 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
  16. 16. 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
  17. 17. Code
  18. 18. SharePoint 2013 REST - jQuery jQuery.ajax({ url: “http://site url/_api/web/lists”, type: “GET”, headers: { “ACCEPT”: “application/json;odata=verbose”, “Authorization”: “Bearer “ + accessToken }, })
  19. 19. 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 }
  20. 20. 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();
  21. 21. Show Me The Money
  22. 22. Thoughts
  23. 23. Thoughts Feature .NET Framework / Silverlight object 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 platform No, from JavaScript Leveraging jQuery, Knockout, and other JavaScript libraries No Yes No, from Windows platform Yes, from JavaScript
  24. 24. 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
  25. 25. Resources • rest-api-anonymous-users • • • • •
  26. 26. 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
  27. 27. Thank You to the Sponsors
  28. 28. Thank You
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.