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
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
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