SlideShare uma empresa Scribd logo
1 de 18
Moving from SOAP to Rest:
You’ve Got to Do It
Sometime
Marc D Anderson
President
Sympraxis Consulting LLC
Who Is Marc?
 Co-Founder and President of Sympraxis Consulting LLC,
located in the Boston suburb of Newton, MA, USA.
Sympraxis focuses on enabling collaboration throughout
the enterprise using the SharePoint application platform.
 Over 30 years of experience in technology professional
services and software development. Over a wide-ranging
career in consulting as well as line manager positions, Marc
has proven himself as a problem solver and leader who
can solve difficult technology problems for organizations
across a wide variety of industries and organization sizes.
 Author of SPServices
 Awarded Microsoft MVP for SharePoint Server 2011-2015
Contact Information
Email marc.anderson@sympraxisconsulting.com
Twitter @sympmarc
Blog http://sympmarc.com
SPServices http://spservices.codeplex.com
SPXSLT http://spxslt.codeplex.com
Books http://sympmarc.com/books
The Middle Tier Manifesto http://bit.ly/middletier
Session Overview
 If you’ve been developing client side applications or
functionality using SPServices and the SOAP Web Services,
sooner or later you’ll want to move to REST instead.
 This session takes the patterns shown in my article series
on ITUnity and my blog and makes it real with real-world
examples. There are some things you can do now to
prepare for this eventuality, whether it’s part of an upgrade
to SharePoint 2013 or simply because you’ve got “legacy”
code that uses SOAP instead of REST.
 We’ll go through the decision points, specific code
examples, and better practices.
Why Move from SOAP to REST?
 SOAP
 Simple Object Access Protocol
 Created 1998 by Dave Winer et al for Microsoft
 Discoverability via WSDL
 XML-based
 REST
 Representational State Transfer
 Odata protocols
 JSON
 Much wider usage
Sources: http://en.wikipedia.org/wiki/SOAP#History, http://en.wikipedia.org/wiki/Representational_state_transfer
Services Across SharePoint
Versions
SOAP REST
Deprecated
Deprecated
REST Endpoint
/_vti_bin/listdata.svc
/_api
SOAP Services
Source: https://spservices.codeplex.com/wikipage?title=$().SPServices
Conversion Approaches
 Abstract data access (SPServices) calls
 Get familiar with promises
 Begin using JSON
 Convert individual calls – mix and match
 Start new development with REST – spackle
with CSOM or SOAP
Abstract Data Access
$.fn.TasksApp.Tasks.delete = function(options) {
var opt = $.extend({}, {
task: null
}, $.fn.TasksApp.defaults, options);
var result = $.Deferred();
var p = $().SPServices({
operation: "UpdateListItems",
listName: opt.tasksList,
batchCmd: "Delete",
ID: opt.task.ID
});
p.done(function() {
var errorCode = $(p.responseXML).find("Result >
ErrorCode").text();
if (errorCode === "0x00000000") {
// Success
result.resolveWith(opt.task.ID);
} else {
// Something went wrong
result.resolveWith(-1);
}
});
return result.promise();
}; // End $.fn.TasksApp.Tasks.delete
SOAP
Replace When Ready
$.fn.TasksApp.Tasks.delete = function(options) {
var opt = $.extend({}, {
task: null
}, $.fn.TasksApp.defaults, options);
var result = $.Deferred();
var p = $().SPServices({
operation: "UpdateListItems",
listName: opt.tasksList,
batchCmd: "Delete",
ID: opt.task.ID
});
p.done(function() {
var errorCode = $(p.responseXML).find("Result >
ErrorCode").text();
if (errorCode === "0x00000000") {
// Success
result.resolveWith(opt.task.ID);
} else {
// Something went wrong
result.resolveWith(-1);
}
});
return result.promise();
}; // End $.fn.TasksApp.Tasks.delete
$.fn.TasksApp.Tasks.delete = function(options) {
var opt = $.extend({}, {
task: null
}, $.fn.TasksApp.defaults, options);
var result = $.Deferred();
var p = $.ajax({
url: "http://siteurl/_api/web/lists/GetByTitle('Tasks')/items(" +
opt.task.ID + ")",
method: "POST",
headers: {
Authorization: "Bearer " + accessToken
X-RequestDigest: form digest value
"IF-MATCH": etag or "*"
"X-HTTP-Method":"DELETE"}
});
p.done(function() {
var errorCode = $(p.responseXML).find("Result >
ErrorCode").text();
if (errorCode === "0x00000000") {
// Success
result.resolveWith(opt.ID);
} else {
// Something went wrong
result.resolveWith(-1);
}
});
return result.promise();
}; // End $.fn.TasksApp.tasks.delete
SOAP
REST
How Does SOAP Map to REST?
SOAPREST
Mapping GetListItems: The Nitty-Gritty
SOAP Option
(SPServices synonym)
REST Comments
ViewFields
(CAMLViewFields)
$select Choose the columns you would like to retrieve. With both SOAP and REST we get some data
we don’t explicitly request, but by specifying only the columns we need we can reduce the
payload sizes.
Query
(CAMLQuery)
$filter,
$orderby
Specify which items in the list we would like to return and how we would like them sorted.
RowLimit
(CAMLRowLimit)
$limit Say how many items matching the Query we would like to receive. In SOAP we can specify 0
to get all matching items; in REST we can omit the parameter to get all the matching items.
Otherwise, we can specify any integer as the limit.
ViewName
(CAMLViewName)
NA ViewName lets you choose the view you would like to get in the response. There’s no REST
equivalent here. I’ve always discouraged using this option in SOAP because it’s too easy to
change the view settings and cause unintended consequences.
QueryOptions
(CAMLQueryOptions)
NA In SOAP, this lets us specify some options that change how the data is returned to us. For
example, we can ask for all of the attachment URLs rather than just a Boolean which tells us
that there are attachments.
NA $expand This option in REST has no direct equivalent in SOAP. $expand allows us to indicate that we
would like the values for a relationship - rather than just the indices - using a projection. This
is important with Lookup columns and Person or Group columns.
Generic Read Function
SPServices: XML vs. JSON
JSON
SPGetListItemsJson
XML
GetListItems
REST: JSON
JSON
REST
We’ll look at a live example showing the different ways we can request
data, along with the conversion approaches.
Resources
 SharePoint 2013 – CRUD on List Items Using
REST Services & jQuery
 Get started with the SharePoint 2013 REST
service
 Working with lists and list items with REST
 Use OData query operations in SharePoint
REST requests
Thank you for attending!
Marc D Anderson

Mais conteúdo relacionado

Semelhante a SharePoint Evolutions 2015 - Moving from SOAP to REST

Sql interview question part 12
Sql interview question part 12Sql interview question part 12
Sql interview question part 12
kaashiv1
 
Summer '16 Realease notes
Summer '16 Realease notesSummer '16 Realease notes
Summer '16 Realease notes
aggopal1011
 
Building social and RESTful frameworks
Building social and RESTful frameworksBuilding social and RESTful frameworks
Building social and RESTful frameworks
brendonschwartz
 
SharePoint 2010 Application Development Overview
SharePoint 2010 Application Development OverviewSharePoint 2010 Application Development Overview
SharePoint 2010 Application Development Overview
Rob Windsor
 
Modeling Search Computing Applications
Modeling Search Computing ApplicationsModeling Search Computing Applications
Modeling Search Computing Applications
Marco Brambilla
 

Semelhante a SharePoint Evolutions 2015 - Moving from SOAP to REST (20)

Collab365 Oct 2015 - Moving from SOAP to REST – You’ll Have to Do It Sometime
Collab365 Oct 2015 - Moving from SOAP to REST – You’ll Have to Do It SometimeCollab365 Oct 2015 - Moving from SOAP to REST – You’ll Have to Do It Sometime
Collab365 Oct 2015 - Moving from SOAP to REST – You’ll Have to Do It Sometime
 
SharePoint Saturday Boston 2015 - Moving from SOAP to REST
SharePoint Saturday Boston 2015 - Moving from SOAP to RESTSharePoint Saturday Boston 2015 - Moving from SOAP to REST
SharePoint Saturday Boston 2015 - Moving from SOAP to REST
 
Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)
 
Hard learned CSOM and REST tips
Hard learned CSOM and REST tipsHard learned CSOM and REST tips
Hard learned CSOM and REST tips
 
Sql interview question part 12
Sql interview question part 12Sql interview question part 12
Sql interview question part 12
 
Ebook12
Ebook12Ebook12
Ebook12
 
Sql interview question part 12
Sql interview question part 12Sql interview question part 12
Sql interview question part 12
 
Web services soap and rest by mandakini for TechGig
Web services soap and rest by mandakini for TechGigWeb services soap and rest by mandakini for TechGig
Web services soap and rest by mandakini for TechGig
 
SQL vs SOQL for Salesforce Analytics
SQL vs SOQL for Salesforce AnalyticsSQL vs SOQL for Salesforce Analytics
SQL vs SOQL for Salesforce Analytics
 
MuleSoft London Community February 2020 - MuleSoft and OData
MuleSoft London Community February 2020 - MuleSoft and ODataMuleSoft London Community February 2020 - MuleSoft and OData
MuleSoft London Community February 2020 - MuleSoft and OData
 
A4 from rad to mvc
A4 from rad to mvcA4 from rad to mvc
A4 from rad to mvc
 
Summer '16 Realease notes
Summer '16 Realease notesSummer '16 Realease notes
Summer '16 Realease notes
 
Building social and RESTful frameworks
Building social and RESTful frameworksBuilding social and RESTful frameworks
Building social and RESTful frameworks
 
SharePoint 2010 Application Development Overview
SharePoint 2010 Application Development OverviewSharePoint 2010 Application Development Overview
SharePoint 2010 Application Development Overview
 
Building RESTful Applications with OData
Building RESTful Applications with ODataBuilding RESTful Applications with OData
Building RESTful Applications with OData
 
REST: So What's It All About? (SAP TechEd 2011, MOB107)
REST: So What's It All About? (SAP TechEd 2011, MOB107)REST: So What's It All About? (SAP TechEd 2011, MOB107)
REST: So What's It All About? (SAP TechEd 2011, MOB107)
 
SAS Online Training Institute in Hyderabad - C-Point
SAS Online Training Institute in Hyderabad - C-PointSAS Online Training Institute in Hyderabad - C-Point
SAS Online Training Institute in Hyderabad - C-Point
 
Introduction to AWS Step Functions
Introduction to AWS Step FunctionsIntroduction to AWS Step Functions
Introduction to AWS Step Functions
 
OData for iOS developers
OData for iOS developersOData for iOS developers
OData for iOS developers
 
Modeling Search Computing Applications
Modeling Search Computing ApplicationsModeling Search Computing Applications
Modeling Search Computing Applications
 

Mais de Marc D Anderson

Mais de Marc D Anderson (20)

SPC2019 - Managing Content Types in the Modern World
SPC2019 - Managing Content Types in the Modern WorldSPC2019 - Managing Content Types in the Modern World
SPC2019 - Managing Content Types in the Modern World
 
ECS2019 - Managing Content Types in the Modern World
ECS2019 - Managing Content Types in the Modern WorldECS2019 - Managing Content Types in the Modern World
ECS2019 - Managing Content Types in the Modern World
 
Rencontre Groupe d'usagers SharePoint Montreal - The Next Great Migration - C...
Rencontre Groupe d'usagers SharePoint Montreal - The Next Great Migration - C...Rencontre Groupe d'usagers SharePoint Montreal - The Next Great Migration - C...
Rencontre Groupe d'usagers SharePoint Montreal - The Next Great Migration - C...
 
RISPUG - Top Form - Using PowerApps to Replace List Forms
RISPUG - Top Form - Using PowerApps to Replace List FormsRISPUG - Top Form - Using PowerApps to Replace List Forms
RISPUG - Top Form - Using PowerApps to Replace List Forms
 
SPCNA 2018 - Top Form - Using PowerApps to Replace List Forms
SPCNA 2018 - Top Form - Using PowerApps to Replace List FormsSPCNA 2018 - Top Form - Using PowerApps to Replace List Forms
SPCNA 2018 - Top Form - Using PowerApps to Replace List Forms
 
SPCNA 2018 - The Next Great Migration - Classic to Modern
SPCNA 2018 - The Next Great Migration - Classic to ModernSPCNA 2018 - The Next Great Migration - Classic to Modern
SPCNA 2018 - The Next Great Migration - Classic to Modern
 
SPS New York City 2017 - The Lay of the Land of Client-Side Development circa...
SPS New York City 2017 - The Lay of the Land of Client-Side Development circa...SPS New York City 2017 - The Lay of the Land of Client-Side Development circa...
SPS New York City 2017 - The Lay of the Land of Client-Side Development circa...
 
ECS Zagreb 2017 - Content Types - Love Them or Lose It
ECS Zagreb 2017 - Content Types - Love Them or Lose ItECS Zagreb 2017 - Content Types - Love Them or Lose It
ECS Zagreb 2017 - Content Types - Love Them or Lose It
 
SPS Monaco 2017 - The Lay of the Land of Client-Side Development circa 2017
SPS Monaco 2017 - The Lay of the Land of Client-Side Development circa 2017SPS Monaco 2017 - The Lay of the Land of Client-Side Development circa 2017
SPS Monaco 2017 - The Lay of the Land of Client-Side Development circa 2017
 
Lions Tigers Teams - SPTechCon Austin 2017
Lions Tigers Teams - SPTechCon Austin 2017Lions Tigers Teams - SPTechCon Austin 2017
Lions Tigers Teams - SPTechCon Austin 2017
 
Oslo SP User Group - Content Types - Love Them or Lose It
Oslo SP User Group - Content Types - Love Them or Lose ItOslo SP User Group - Content Types - Love Them or Lose It
Oslo SP User Group - Content Types - Love Them or Lose It
 
Unity Connect Haarlem 2016 - The Lay of the Land of Client-Side Development c...
Unity Connect Haarlem 2016 - The Lay of the Land of Client-Side Development c...Unity Connect Haarlem 2016 - The Lay of the Land of Client-Side Development c...
Unity Connect Haarlem 2016 - The Lay of the Land of Client-Side Development c...
 
SPTechCon Boston 2016 - Creating a Great User Experience in SharePoint
SPTechCon Boston 2016 - Creating a Great User Experience in SharePointSPTechCon Boston 2016 - Creating a Great User Experience in SharePoint
SPTechCon Boston 2016 - Creating a Great User Experience in SharePoint
 
SPTechCon Boston 2016 - Content Types - Love Them or Lose It
SPTechCon Boston 2016 - Content Types - Love Them or Lose ItSPTechCon Boston 2016 - Content Types - Love Them or Lose It
SPTechCon Boston 2016 - Content Types - Love Them or Lose It
 
SPC Adriatics 2016 - Creating a Great User Experience in SharePoint
SPC Adriatics 2016 - Creating a Great User Experience in SharePointSPC Adriatics 2016 - Creating a Great User Experience in SharePoint
SPC Adriatics 2016 - Creating a Great User Experience in SharePoint
 
SPC Adriatics 2016 - Alternative Approaches to Solution Development in Office...
SPC Adriatics 2016 - Alternative Approaches to Solution Development in Office...SPC Adriatics 2016 - Alternative Approaches to Solution Development in Office...
SPC Adriatics 2016 - Alternative Approaches to Solution Development in Office...
 
SharePointFest Konferenz 2016 - Creating a Great User Experience in SharePoint
SharePointFest Konferenz 2016 - Creating a Great User Experience in SharePointSharePointFest Konferenz 2016 - Creating a Great User Experience in SharePoint
SharePointFest Konferenz 2016 - Creating a Great User Experience in SharePoint
 
SharePointFest Konferenz 2016 - Alternative Approaches to Solution Developmen...
SharePointFest Konferenz 2016 - Alternative Approaches to Solution Developmen...SharePointFest Konferenz 2016 - Alternative Approaches to Solution Developmen...
SharePointFest Konferenz 2016 - Alternative Approaches to Solution Developmen...
 
SPTechCon Austin 2016 - Content Types-Love Them or Lose It
SPTechCon Austin 2016 - Content Types-Love Them or Lose ItSPTechCon Austin 2016 - Content Types-Love Them or Lose It
SPTechCon Austin 2016 - Content Types-Love Them or Lose It
 
SPTechCon Austin 2016 - Creating a Great User Experience in SharePoint
SPTechCon Austin 2016 - Creating a Great User Experience in SharePointSPTechCon Austin 2016 - Creating a Great User Experience in SharePoint
SPTechCon Austin 2016 - Creating a Great User Experience in SharePoint
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

SharePoint Evolutions 2015 - Moving from SOAP to REST

  • 1. Moving from SOAP to Rest: You’ve Got to Do It Sometime Marc D Anderson President Sympraxis Consulting LLC
  • 2. Who Is Marc?  Co-Founder and President of Sympraxis Consulting LLC, located in the Boston suburb of Newton, MA, USA. Sympraxis focuses on enabling collaboration throughout the enterprise using the SharePoint application platform.  Over 30 years of experience in technology professional services and software development. Over a wide-ranging career in consulting as well as line manager positions, Marc has proven himself as a problem solver and leader who can solve difficult technology problems for organizations across a wide variety of industries and organization sizes.  Author of SPServices  Awarded Microsoft MVP for SharePoint Server 2011-2015
  • 3. Contact Information Email marc.anderson@sympraxisconsulting.com Twitter @sympmarc Blog http://sympmarc.com SPServices http://spservices.codeplex.com SPXSLT http://spxslt.codeplex.com Books http://sympmarc.com/books The Middle Tier Manifesto http://bit.ly/middletier
  • 4. Session Overview  If you’ve been developing client side applications or functionality using SPServices and the SOAP Web Services, sooner or later you’ll want to move to REST instead.  This session takes the patterns shown in my article series on ITUnity and my blog and makes it real with real-world examples. There are some things you can do now to prepare for this eventuality, whether it’s part of an upgrade to SharePoint 2013 or simply because you’ve got “legacy” code that uses SOAP instead of REST.  We’ll go through the decision points, specific code examples, and better practices.
  • 5. Why Move from SOAP to REST?  SOAP  Simple Object Access Protocol  Created 1998 by Dave Winer et al for Microsoft  Discoverability via WSDL  XML-based  REST  Representational State Transfer  Odata protocols  JSON  Much wider usage Sources: http://en.wikipedia.org/wiki/SOAP#History, http://en.wikipedia.org/wiki/Representational_state_transfer
  • 6. Services Across SharePoint Versions SOAP REST Deprecated Deprecated REST Endpoint /_vti_bin/listdata.svc /_api
  • 8. Conversion Approaches  Abstract data access (SPServices) calls  Get familiar with promises  Begin using JSON  Convert individual calls – mix and match  Start new development with REST – spackle with CSOM or SOAP
  • 9. Abstract Data Access $.fn.TasksApp.Tasks.delete = function(options) { var opt = $.extend({}, { task: null }, $.fn.TasksApp.defaults, options); var result = $.Deferred(); var p = $().SPServices({ operation: "UpdateListItems", listName: opt.tasksList, batchCmd: "Delete", ID: opt.task.ID }); p.done(function() { var errorCode = $(p.responseXML).find("Result > ErrorCode").text(); if (errorCode === "0x00000000") { // Success result.resolveWith(opt.task.ID); } else { // Something went wrong result.resolveWith(-1); } }); return result.promise(); }; // End $.fn.TasksApp.Tasks.delete SOAP
  • 10. Replace When Ready $.fn.TasksApp.Tasks.delete = function(options) { var opt = $.extend({}, { task: null }, $.fn.TasksApp.defaults, options); var result = $.Deferred(); var p = $().SPServices({ operation: "UpdateListItems", listName: opt.tasksList, batchCmd: "Delete", ID: opt.task.ID }); p.done(function() { var errorCode = $(p.responseXML).find("Result > ErrorCode").text(); if (errorCode === "0x00000000") { // Success result.resolveWith(opt.task.ID); } else { // Something went wrong result.resolveWith(-1); } }); return result.promise(); }; // End $.fn.TasksApp.Tasks.delete $.fn.TasksApp.Tasks.delete = function(options) { var opt = $.extend({}, { task: null }, $.fn.TasksApp.defaults, options); var result = $.Deferred(); var p = $.ajax({ url: "http://siteurl/_api/web/lists/GetByTitle('Tasks')/items(" + opt.task.ID + ")", method: "POST", headers: { Authorization: "Bearer " + accessToken X-RequestDigest: form digest value "IF-MATCH": etag or "*" "X-HTTP-Method":"DELETE"} }); p.done(function() { var errorCode = $(p.responseXML).find("Result > ErrorCode").text(); if (errorCode === "0x00000000") { // Success result.resolveWith(opt.ID); } else { // Something went wrong result.resolveWith(-1); } }); return result.promise(); }; // End $.fn.TasksApp.tasks.delete SOAP REST
  • 11. How Does SOAP Map to REST? SOAPREST
  • 12. Mapping GetListItems: The Nitty-Gritty SOAP Option (SPServices synonym) REST Comments ViewFields (CAMLViewFields) $select Choose the columns you would like to retrieve. With both SOAP and REST we get some data we don’t explicitly request, but by specifying only the columns we need we can reduce the payload sizes. Query (CAMLQuery) $filter, $orderby Specify which items in the list we would like to return and how we would like them sorted. RowLimit (CAMLRowLimit) $limit Say how many items matching the Query we would like to receive. In SOAP we can specify 0 to get all matching items; in REST we can omit the parameter to get all the matching items. Otherwise, we can specify any integer as the limit. ViewName (CAMLViewName) NA ViewName lets you choose the view you would like to get in the response. There’s no REST equivalent here. I’ve always discouraged using this option in SOAP because it’s too easy to change the view settings and cause unintended consequences. QueryOptions (CAMLQueryOptions) NA In SOAP, this lets us specify some options that change how the data is returned to us. For example, we can ask for all of the attachment URLs rather than just a Boolean which tells us that there are attachments. NA $expand This option in REST has no direct equivalent in SOAP. $expand allows us to indicate that we would like the values for a relationship - rather than just the indices - using a projection. This is important with Lookup columns and Person or Group columns.
  • 14. SPServices: XML vs. JSON JSON SPGetListItemsJson XML GetListItems
  • 16. We’ll look at a live example showing the different ways we can request data, along with the conversion approaches.
  • 17. Resources  SharePoint 2013 – CRUD on List Items Using REST Services & jQuery  Get started with the SharePoint 2013 REST service  Working with lists and list items with REST  Use OData query operations in SharePoint REST requests
  • 18. Thank you for attending! Marc D Anderson