Skip to content

Transformer - HTTP/REST

Description

The HTTP/REST transformer is designed to facilitate the integration of external RESTful APIs into Apiro feeds. This transformer allows for the extraction of data from web services by making HTTP requests to specified endpoints. It supports the methods: GET, POST, and can handle both JSON and XML data formats. This transformer is particularly useful for integrating data from third-party services, such as financial data providers or any other web-based data sources.


Config

Parameters

Parameter Type Default Description
url String N/A The URL of the REST API endpoint.
method String GET The HTTP method to use for the request (e.g., GET, POST).
listPath String N/A The selector which determines the base html element to source from

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<apiroConf version="1" xmlns="http://apiro.com/apiro/v1/root">
    <groups>test blah</groups>
    <loadOrder>20</loadOrder>
    <dataFeeds>
        <dataFeed definition="EXPR_HTML_FEED" name="ASX200_LIST">
            <execPriority>10</execPriority>
            <enabled>true</enabled>
            <push>false</push>
            <pull>true</pull>
            <schema>ASX200</schema>
            <cronTriggers>
            </cronTriggers>
            <config><![CDATA[
{
  "dataSource": {
    "entity": "REST",
    "config": {
      "url": "https://www.asx200list.com/",
      "method": "GET"
    }
  },
  "itemLimit": 27,
  "listPath" : "table.tableizer-table tr",
                    "explicitMappings": [
                    {
                            "dictionary": "code",
                            "value": "#{PAYLOAD.resolve('td:eq(0)')}"
                        },
                        {
                            "dictionary": "name",
                            "value": "#{PAYLOAD.resolve('td:eq(1)')}"
                        }
                    ]
                }
]]>
            </config>
        </dataFeed>
    </dataFeeds>
</apiroConf>

Here is a concise portion of the above example, including only the direct structure of the transformer:

1
2
3
{
  "listPath" : "table.tableizer-table tr"
}

Common Mistakes

  • Incorrect URL: Ensure that the url parameter is correctly set to the endpoint of the REST API you are trying to access.
  • Unsupported HTTP Method: Verify that the method parameter matches the HTTP method supported by the REST API endpoint.
  • Incorrect Data Extraction Path: The listPath parameter should accurately reflect the structure of the HTML or JSON response to correctly extract the desired data.