SlideShare a Scribd company logo
1 of 12
(APEX) REST API 
Boris Bachovski 
Developer/Consultant – Deloitte 
@bachovski
REST API vs APEX REST API
What you can do 
- Lets you integrate Force.com applications using HTTP methods 
- GET, POST, PUT, PATCH, DELETE, HEAD 
- Synchronous 
- Data format: XML OR JSON 
- Authentication using: oAuth 2.0 or Session ID 
- OOTB CRUD support for your objects 
What you can’t do 
- Complex SOQL queries * 
- Custom logic or rules * 
- Anonymous Access *
Benefits 
- Convenient, Simple 
- Get started within minutes 
- Minimise round trips to the server – crucial for mobile applications 
Things to consider 
- Governor limits – counts towards the API request limit for the org 
- Max response payload size (3MB)
How it works 
- REST API - https://instance.salesforce.com/services/data/vXX.X/ 
- limits 
- sobjects 
- connect 
- query 
- theme 
- queryAll 
- tooling 
- chatter 
- analytics 
- recent 
- licensing 
- identity 
- flexiPage 
- search 
- quickActions 
- appMenu 
- APEX REST API - https://instance.salesforce.com/services/apexrest/methodname
REST API DEMO
Expose Custom Apex Logic 
as RESTful Web Service 
Key Characteristics: 
- Define your own URI 
- Authentication (oAuth or Session ID) 
- Built-in (de)serialisation for JSON and XML 
- Case sensitive data keys (parameter names) 
- You can’t have more than 1 of the same HTTP method in the same class 
- You can have multiple classes with the same URI (the most recent one will be valid)
Annotations 
Annotation Description Incoming Data 
@RestResource 
(urlMapping=“yourURL”) 
Defines the class as a custom 
Apex endpoint. 
None 
@HttpGet 
Defines the function to be called via 
HTTP GET – Usually to retrieve a 
resource 
Query Parameters in the URL 
@HttpDelete 
Defines the function to be called via 
HTTP DELETE – Usually to delete a 
resource 
Query Parameters in the URL 
@HttpPost 
Defines the function to be called via 
HTTP POST – Usually to create a new 
resource 
POST Data (body) in JSON/XML 
@HttpPatch 
Defines the function to be called via 
HTTP PUT – Usually to partially 
update a resource 
POST Data (body) in JSON/XML 
@HttpPut 
Defines the function to be called via 
HTTP PATCH – Usually to fully update 
a resource 
POST Data (body) in JSON/XML
Best Practices 
- URI Naming Convention and Versioning 
- Don’t ignore the “with sharing” access modifier 
- Don’t forget to enable the classes for each user profile that needs access 
(if the web service is exposed publicly) 
- Bulkify the code in order to minimise traffic and API calls
APEX REST API DEMO
QUESTIONS?
Resources 
Getting Started with the Force.com REST API 
- https://www.salesforce.com/us/developer/docs/api_rest/index_Left.htm#StartTopic=Content/quickstart.htm 
Apex REST Basic Code Sample 
- https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_rest_code_sample_basic.htm 
Creating REST APIs using Apex REST 
- https://developer.salesforce.com/page/Creating_REST_APIs_using_Apex_REST 
Creating Anonymous Apex REST APIs with Force.com 
- http://www.wadewegner.com/2013/03/creating-anonymous-rest-apis-with-salesforce-com/ 
Interact with the Force.com REST API from PHP 
- http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php 
Force.com REST API Cheat Sheet 
- http://res.cloudinary.com/hy4kyit2a/image/upload/SF_rest_api_cheatsheet.pdf 
Workbench Tool 
- https://workbench.developerforce.com

More Related Content

What's hot

Single page apps_with_cf_and_angular[1]
Single page apps_with_cf_and_angular[1]Single page apps_with_cf_and_angular[1]
Single page apps_with_cf_and_angular[1]
ColdFusionConference
 

What's hot (20)

Have Some Rest Building Web2.0 Apps And Services
Have Some Rest   Building Web2.0 Apps And ServicesHave Some Rest   Building Web2.0 Apps And Services
Have Some Rest Building Web2.0 Apps And Services
 
Demystify Salesforce Bulk API
Demystify Salesforce Bulk APIDemystify Salesforce Bulk API
Demystify Salesforce Bulk API
 
Single page apps_with_cf_and_angular[1]
Single page apps_with_cf_and_angular[1]Single page apps_with_cf_and_angular[1]
Single page apps_with_cf_and_angular[1]
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & Development
 
LeverX SAP ABAP Tutorial - Creating and Calling Web Services
LeverX SAP ABAP Tutorial - Creating and Calling Web ServicesLeverX SAP ABAP Tutorial - Creating and Calling Web Services
LeverX SAP ABAP Tutorial - Creating and Calling Web Services
 
REST full API Design
REST full API DesignREST full API Design
REST full API Design
 
SPCA2013 - Developing Provider-Hosted Apps for SharePoint 2013
SPCA2013 - Developing Provider-Hosted Apps for SharePoint 2013SPCA2013 - Developing Provider-Hosted Apps for SharePoint 2013
SPCA2013 - Developing Provider-Hosted Apps for SharePoint 2013
 
Query Operation in Microsoft SharePoint using Mule ESB
Query Operation in Microsoft SharePoint using Mule ESBQuery Operation in Microsoft SharePoint using Mule ESB
Query Operation in Microsoft SharePoint using Mule ESB
 
Designing for SharePoint Provider Hosted Apps
Designing for SharePoint Provider Hosted AppsDesigning for SharePoint Provider Hosted Apps
Designing for SharePoint Provider Hosted Apps
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 
SharePoint Client Object Model (CSOM)
SharePoint Client Object Model (CSOM)SharePoint Client Object Model (CSOM)
SharePoint Client Object Model (CSOM)
 
Mule esb stripe
Mule esb stripeMule esb stripe
Mule esb stripe
 
Integration with Microsoft CRM using Mule ESB
Integration with Microsoft CRM using Mule ESBIntegration with Microsoft CRM using Mule ESB
Integration with Microsoft CRM using Mule ESB
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
Introduction to the Client OM in SharePoint 2010
Introduction to the Client OM in SharePoint 2010Introduction to the Client OM in SharePoint 2010
Introduction to the Client OM in SharePoint 2010
 
SharePoint 2013 REST APIs
SharePoint 2013 REST APIsSharePoint 2013 REST APIs
SharePoint 2013 REST APIs
 
Get Some Rest - Taking Advantage of the SharePoint 2013 REST API
Get Some Rest - Taking Advantage of the SharePoint 2013 REST APIGet Some Rest - Taking Advantage of the SharePoint 2013 REST API
Get Some Rest - Taking Advantage of the SharePoint 2013 REST API
 
Web API testing : A quick glance
Web API testing : A quick glanceWeb API testing : A quick glance
Web API testing : A quick glance
 
ITB2016 - Building ColdFusion RESTFul Services
ITB2016 - Building ColdFusion RESTFul ServicesITB2016 - Building ColdFusion RESTFul Services
ITB2016 - Building ColdFusion RESTFul Services
 
Get Data from Microsoft CRM using Mule ESB
Get Data from Microsoft CRM using Mule ESBGet Data from Microsoft CRM using Mule ESB
Get Data from Microsoft CRM using Mule ESB
 

Similar to Apex REST

RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
Li Yi
 
Are you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint AppsAre you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint Apps
Liam Cleary [MVP]
 

Similar to Apex REST (20)

Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
 
Rest with Spring
Rest with SpringRest with Spring
Rest with Spring
 
WebApp #3 : API
WebApp #3 : APIWebApp #3 : API
WebApp #3 : API
 
Xamarin Workshop Noob to Master – Week 5
Xamarin Workshop Noob to Master – Week 5Xamarin Workshop Noob to Master – Week 5
Xamarin Workshop Noob to Master – Week 5
 
Lunacloud's Compute RESTful API - Programmer's Guide
Lunacloud's Compute RESTful API - Programmer's GuideLunacloud's Compute RESTful API - Programmer's Guide
Lunacloud's Compute RESTful API - Programmer's Guide
 
OpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML ResourcesOpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML Resources
 
Design Summit - RESTful API Overview - John Hardy
Design Summit - RESTful API Overview - John HardyDesign Summit - RESTful API Overview - John Hardy
Design Summit - RESTful API Overview - John Hardy
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
 
KaTe RESTful adapter for SAP Process Integration: Introduction
KaTe RESTful adapter for SAP Process Integration: IntroductionKaTe RESTful adapter for SAP Process Integration: Introduction
KaTe RESTful adapter for SAP Process Integration: Introduction
 
Asec r01-resting-on-your-laurels-will-get-you-pwned
Asec r01-resting-on-your-laurels-will-get-you-pwnedAsec r01-resting-on-your-laurels-will-get-you-pwned
Asec r01-resting-on-your-laurels-will-get-you-pwned
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
 
Api design and development
Api design and developmentApi design and development
Api design and development
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
Resting on your laurels will get you powned
Resting on your laurels will get you pownedResting on your laurels will get you powned
Resting on your laurels will get you powned
 
How to call REST API without knowing any programming languages
How to call REST API without knowing any programming languages How to call REST API without knowing any programming languages
How to call REST API without knowing any programming languages
 
Are you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint AppsAre you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint Apps
 
A Conversation About REST
A Conversation About RESTA Conversation About REST
A Conversation About REST
 
A Conversation About REST
A Conversation About RESTA Conversation About REST
A Conversation About REST
 
CDI, Seam & RESTEasy: You haven't seen REST yet!
CDI, Seam & RESTEasy: You haven't seen REST yet!CDI, Seam & RESTEasy: You haven't seen REST yet!
CDI, Seam & RESTEasy: You haven't seen REST yet!
 

Recently uploaded

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Recently uploaded (20)

WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 

Apex REST

  • 1. (APEX) REST API Boris Bachovski Developer/Consultant – Deloitte @bachovski
  • 2. REST API vs APEX REST API
  • 3. What you can do - Lets you integrate Force.com applications using HTTP methods - GET, POST, PUT, PATCH, DELETE, HEAD - Synchronous - Data format: XML OR JSON - Authentication using: oAuth 2.0 or Session ID - OOTB CRUD support for your objects What you can’t do - Complex SOQL queries * - Custom logic or rules * - Anonymous Access *
  • 4. Benefits - Convenient, Simple - Get started within minutes - Minimise round trips to the server – crucial for mobile applications Things to consider - Governor limits – counts towards the API request limit for the org - Max response payload size (3MB)
  • 5. How it works - REST API - https://instance.salesforce.com/services/data/vXX.X/ - limits - sobjects - connect - query - theme - queryAll - tooling - chatter - analytics - recent - licensing - identity - flexiPage - search - quickActions - appMenu - APEX REST API - https://instance.salesforce.com/services/apexrest/methodname
  • 7. Expose Custom Apex Logic as RESTful Web Service Key Characteristics: - Define your own URI - Authentication (oAuth or Session ID) - Built-in (de)serialisation for JSON and XML - Case sensitive data keys (parameter names) - You can’t have more than 1 of the same HTTP method in the same class - You can have multiple classes with the same URI (the most recent one will be valid)
  • 8. Annotations Annotation Description Incoming Data @RestResource (urlMapping=“yourURL”) Defines the class as a custom Apex endpoint. None @HttpGet Defines the function to be called via HTTP GET – Usually to retrieve a resource Query Parameters in the URL @HttpDelete Defines the function to be called via HTTP DELETE – Usually to delete a resource Query Parameters in the URL @HttpPost Defines the function to be called via HTTP POST – Usually to create a new resource POST Data (body) in JSON/XML @HttpPatch Defines the function to be called via HTTP PUT – Usually to partially update a resource POST Data (body) in JSON/XML @HttpPut Defines the function to be called via HTTP PATCH – Usually to fully update a resource POST Data (body) in JSON/XML
  • 9. Best Practices - URI Naming Convention and Versioning - Don’t ignore the “with sharing” access modifier - Don’t forget to enable the classes for each user profile that needs access (if the web service is exposed publicly) - Bulkify the code in order to minimise traffic and API calls
  • 12. Resources Getting Started with the Force.com REST API - https://www.salesforce.com/us/developer/docs/api_rest/index_Left.htm#StartTopic=Content/quickstart.htm Apex REST Basic Code Sample - https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_rest_code_sample_basic.htm Creating REST APIs using Apex REST - https://developer.salesforce.com/page/Creating_REST_APIs_using_Apex_REST Creating Anonymous Apex REST APIs with Force.com - http://www.wadewegner.com/2013/03/creating-anonymous-rest-apis-with-salesforce-com/ Interact with the Force.com REST API from PHP - http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php Force.com REST API Cheat Sheet - http://res.cloudinary.com/hy4kyit2a/image/upload/SF_rest_api_cheatsheet.pdf Workbench Tool - https://workbench.developerforce.com

Editor's Notes

  1. REST API – built in interface on the platform, lets you interact with the existing data out of the box APEX lets you expose classes, methods and custom code for external applications. Building custom logic, rules and queries etc. Representational State Transfer (REST) is a style of software architecture for distributed hypermedia systems such as the World Wide Web
  2. This API provides a way to expose the data you have within your Force.com application to external applications – both mobile and non-mobile. Complex data queries, custom logic or rules, and anonymous access are NOT supported – here comes APEX REST
  3. JSON is default Content Type