REST API provides a powerful, convenient and simple Web Services API to interact with Force.com platform. REST API uses same underlying data model and standard objects as those in SOAP API.They also follow the same limits as SOAP API.
Advantages of using Force.com REST API
- Ease of integration.
- Ease of development.
- It works great with mobile application and Web2.0 projects.
Note: If you have many records to process, consider using Bulk API. Bulk API is also based on REST principles and optimized for large sets of data.
Table of Contents
ToggleForce.com REST Resources:
What is a REST resource?
A REST resource is an abstraction of a piece of information or an action, such as a single data record, a collection of records, or a query.Every resource in REST API is identified by a named Uniform Resource Identifier and the resource is accessed using standard HTTP methods (HEAD, GET, POST, PATCH, DELETE).
You use a REST resource to interact with your Salesforce org. For example, you can:
1) Fetch summary information about the API version available to you.
2) Retrieve detailed information about a Salesforce object, like Account, User or any custom object.
3) To perform a query or search.
4) to update or delete records.
For example, if you want to retrieve information about the Salesforce version, you can submit a request for the versions resource:
curl https://urInstance.salesforce.com/services/data/
Output from the above request:
[ { "version":"20.0", "url":"/services/data/v20.0", "label":"Winter '11" } ... ]
Features of the Force.com REST API resources and architecture:
Stateless: Every request from client to server must contain all the information necessary to understand the request and not use any stored context on the server. However, the representations of the resources are interconnected using URLs which enables the client to progress between states.
Caching Behaviour: Responses are labeled as non-cacheable or cacheable.
Uniform Interface: All resources are accessed via a generic interface over HTTP.
Named Resources: All resources are named using a base URL which follows your Force.com URI.
Layered components: Force.com REST API architecture allows for the existence of intermediaries as proxy servers. They act as gateways to exist between the client and its resources.
Authentication: Force.com REST API supports OAuth 2.0. OAuth 2.0 is an open protocol to allow secure API authorization.
Force.com API supports JSON and XML: JSON is the default. You can use the HTTP ACCEPT header to choose between JSON or XML. You can even append .json or .xml to the URI. For example,/Contact/001D000000INjVe.json.
JSON stands for JavaScript Object Notation.It is supported with UTF-8. Date-time information is in ISO8601 format.
XML serialization is similar to SOAP API. XML requests are supported in UTF-8 and UTF-16 and XML responses are provided in UTF-8.
Friendly URLs: A friendly URL provides an instinctual way to construct REST API requests and minimizes the number of round-trips between your application and Salesforce org. Friendly URLs are available in API version 36.0 or later.
For example, if you are trying to access Contact’s parent record without a friendly URL then you need to request the contact record using the SObject Rows resource. Then you examine the account relationship field to fetch the account ID and request the account record using another call to SObject Rows. But if you use a friendly URL, you can access the account in a single call directly from the contact’s path: /services/data/v36.0/sobjects/contact/id/account
Note: Please check out the complete Salesforce REST API training course for more details.