Apex REST
-
Upload
boris-bachovski -
Category
Software
-
view
365 -
download
1
description
Transcript of Apex REST
![Page 1: Apex REST](https://reader036.fdocuments.net/reader036/viewer/2022082704/55848f9ad8b42a05388b45f0/html5/thumbnails/1.jpg)
(APEX) REST API
Boris BachovskiDeveloper/Consultant – Deloitte@bachovski
![Page 2: Apex REST](https://reader036.fdocuments.net/reader036/viewer/2022082704/55848f9ad8b42a05388b45f0/html5/thumbnails/2.jpg)
REST API vs APEX REST API
![Page 3: Apex REST](https://reader036.fdocuments.net/reader036/viewer/2022082704/55848f9ad8b42a05388b45f0/html5/thumbnails/3.jpg)
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 *
![Page 4: Apex REST](https://reader036.fdocuments.net/reader036/viewer/2022082704/55848f9ad8b42a05388b45f0/html5/thumbnails/4.jpg)
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)
![Page 5: Apex REST](https://reader036.fdocuments.net/reader036/viewer/2022082704/55848f9ad8b42a05388b45f0/html5/thumbnails/5.jpg)
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
![Page 6: Apex REST](https://reader036.fdocuments.net/reader036/viewer/2022082704/55848f9ad8b42a05388b45f0/html5/thumbnails/6.jpg)
REST API DEMO
![Page 7: Apex REST](https://reader036.fdocuments.net/reader036/viewer/2022082704/55848f9ad8b42a05388b45f0/html5/thumbnails/7.jpg)
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)
![Page 8: Apex REST](https://reader036.fdocuments.net/reader036/viewer/2022082704/55848f9ad8b42a05388b45f0/html5/thumbnails/8.jpg)
Annotations
Annotation Description Incoming Data@RestResource
(urlMapping=“yourURL”)Defines the class as a custom
Apex endpoint. None
@HttpGetDefines the function to be called via
HTTP GET – Usually to retrieve a resource
Query Parameters in the URL
@HttpDeleteDefines the function to be called via HTTP DELETE – Usually to delete a
resourceQuery Parameters in the URL
@HttpPostDefines the function to be called via HTTP POST – Usually to create a new
resourcePOST Data (body) in JSON/XML
@HttpPatchDefines the function to be called via
HTTP PUT – Usually to partially update a resource
POST Data (body) in JSON/XML
@HttpPutDefines the function to be called via HTTP PATCH – Usually to fully update
a resourcePOST Data (body) in JSON/XML
![Page 9: Apex REST](https://reader036.fdocuments.net/reader036/viewer/2022082704/55848f9ad8b42a05388b45f0/html5/thumbnails/9.jpg)
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
![Page 10: Apex REST](https://reader036.fdocuments.net/reader036/viewer/2022082704/55848f9ad8b42a05388b45f0/html5/thumbnails/10.jpg)
APEX REST API DEMO
![Page 11: Apex REST](https://reader036.fdocuments.net/reader036/viewer/2022082704/55848f9ad8b42a05388b45f0/html5/thumbnails/11.jpg)
QUESTIONS?
![Page 12: Apex REST](https://reader036.fdocuments.net/reader036/viewer/2022082704/55848f9ad8b42a05388b45f0/html5/thumbnails/12.jpg)
ResourcesGetting 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