13.3.1 Using a Simple HTTP REST Data Source

The Simple HTTP service is the most generic and flexible REST Data Source type APEX offers. By understanding its capabilities and how to configure them, you can confidently integrate with any necessary API.

If the service you need to use supports a GET method, then the Create REST Data Source wizard gives you a head start by automatically discovering the data profile columns based on the JSON response payload. If not, you can always create and configure the REST Data Source manually.

Imagine you need to integrate with a REST API for working with employees with the endpoint URL:
https://example.com/ords/cloudcompanion/emp
For simplicity, assume the endpoint allows public access, knowing you can configure any kind of authentication to access the REST APIs you need to work with. You can examine the payload it returns using a command line tool like curl:
$ curl -L https://example.com/ords/cloudcompanion/emp
This example service responds with the following JSON payload in which replaces repeating elements. There are 14 employees total: notice a count value of 14 and hasMore value of false.
{
  "items": [
    {
      "empno": 7839,
      "ename": "KING",
      "job": "PRESIDENT",
      "mgr": null,
      "hiredate": "1981-11-17T00:00:00Z",
      "sal": 5000,
      "comm": null,
      "deptno": 10,
      "links": [
        {
          "rel": "self",
          "href": "https://example.com/ords/cloudcompanion/emp/7839"
        }
      ]
    },
    ⋮
  ],
  "hasMore": false,
  "limit": 25,
  "offset": 0,
  "count": 14,
  "links": [
    {
      "rel": "self",
      "href": "https://example.com/ords/cloudcompanion/emp/"
    },
    ⋮
  ]
}

Before defining a REST Data Source for the endpoint, consult the documentation for the service to understand whether it supports retrieving data in pages. This service supports using the limit query string parameter to set a page size, and the offset parameter to indicate a number of rows to skip.

This means you can retrieve just the first two employees using the curl command:
$ curl -L "https://example.com/ords/cloudcompanion/emp?limit=2"
To fetch employee rows 3 and 4 use a curl command that skips the first 2 and retrieves up to two more:
$ curl -L "https://example.com/ords/cloudcompanion/emp?offset=2&limit=2"

To create a REST Data Source to work with this API in your APEX application, as shown below, just use Create REST Data Source wizard from the Shared Components > REST Data Sources page. To get started, all you need to enter is the endpoint URL and proceed to the subsequent wizard steps.

Figure 13-5 Defining a New REST Data Source Using Its Endpoint URL