Basic REST Connection Setup

Overview

Defines a connection to an external REST API using HTTP Basic Authentication.

Connection File: connections/erp-system.json

JSON
{
  "name": "erpSystem",
  "type": "rest-basic",
  "url": "https://{{erp.host}}/api",
  "username": "{{erp.username}}",
  "password": "{{erp.password}}"
}

Properties:

erp.host=erp.example.com
erp.username=integration-user
erp.password=secret

Using the Connection in Routes

XML
<routes xmlns="http://camel.apache.org/schema/spring">
    <route id="fetchFromErp">
        <from uri="timer://trigger?repeatCount=1"/>
        <to uri="pfx-rest:get?uri=/products&amp;connection=erpSystem"/>
        <to uri="pfx-csv:unmarshal?header=sku,label,price"/>
        <to uri="pfx-api:loaddata?objectType=P&amp;mapper=productMapper"/>
    </route>
</routes>

Common Pitfalls

  • Use rest-basic for username/password auth; use rest-oauth2 for token-based auth

  • The url is the base URL — the uri= parameter in routes is appended to it

  • For public APIs with no auth, use rest-public type (omit username/password)