Replicate Multiple REST Accounts



Replicate multiple REST accounts to one or many databases.

CData Sync for REST is a stand-alone application that provides solutions for a variety of replication scenarios such as replicating sandbox and production instances into your database. Both Sync for Windows and Sync for Java include a command-line interface (CLI) that makes it easy to manage multiple REST connections. In this article we show how to use the CLI to replicate multiple REST accounts.

Configure REST Connections

You can save connection and email notification settings in an XML configuration file. To replicate multiple REST accounts, use multiple configuration files. Below is an example configuration to replicate REST to SQLite:

Windows

<?xml version="1.0" encoding="UTF-8" ?> <CDataSync> <DatabaseType>SQLite</DatabaseType> <DatabaseProvider>System.Data.SQLite</DatabaseProvider> <ConnectionString>DataModel=Relational;URI=C:/people.xml;Format=XML;</ConnectionString> <ReplicateAll>False</ReplicateAll> <NotificationUserName></NotificationUserName> <DatabaseConnectionString>Data Source=C:\my.db</DatabaseConnectionString> <TaskSchedulerStartTime>09:51</TaskSchedulerStartTime> <TaskSchedulerInterval>Never</TaskSchedulerInterval> </CDataSync>

Java

<?xml version="1.0" encoding="UTF-8" ?> <CDataSync> <DatabaseType>SQLite</DatabaseType> <DatabaseProvider>org.sqlite.JDBC</DatabaseProvider> <ConnectionString>DataModel=Relational;URI=C:/people.xml;Format=XML;</ConnectionString> <ReplicateAll>False</ReplicateAll> <NotificationUserName></NotificationUserName> <DatabaseConnectionString>Data Source=C:\my.db</DatabaseConnectionString> </CDataSync>

See the Getting Started chapter in the data provider documentation to authenticate to your data source: The data provider models REST APIs as bidirectional database tables and XML/JSON files as read-only views (local files, files stored on popular cloud services, and FTP servers). The major authentication schemes are supported, including HTTP Basic, Digest, NTLM, OAuth, and FTP. See the Getting Started chapter in the data provider documentation for authentication guides.

After setting the URI and providing any authentication values, set Format to "XML" or "JSON" and set DataModel to more closely match the data representation to the structure of your data.

The DataModel property is the controlling property over how your data is represented into tables and toggles the following basic configurations.

  • Document (default): Model a top-level, document view of your REST data. The data provider returns nested elements as aggregates of data.
  • FlattenedDocuments: Implicitly join nested documents and their parents into a single table.
  • Relational: Return individual, related tables from hierarchical data. The tables contain a primary key and a foreign key that links to the parent document.

See the Modeling REST Data chapter for more information on configuring the relational representation. You will also find the sample data used in the following examples. The data includes entries for people, the cars they own, and various maintenance services performed on those cars.

Configure Queries for Each REST Instance

Sync enables you to control replication with standard SQL. The REPLICATE statement is a high-level command that caches and maintains a table in your database. You can define any SELECT query supported by the REST API. The statement below caches and incrementally updates a table of REST data:

REPLICATE people;

You can specify a file containing the replication queries you want to use to update a particular database. Separate replication statements with semicolons. The following options are useful if you are replicating multiple REST accounts into the same database:

You can use a different table prefix in the REPLICATE SELECT statement:

REPLICATE PROD_people SELECT * FROM people

Alternatively, you can use a different schema:

REPLICATE PROD.people SELECT * FROM people

Run Sync

After you have configured the connection strings and replication queries, you can run Sync with the following command-line options:

Windows

RESTSync.exe -g MyProductionRESTConfig.xml -f MyProductionRESTSync.sql

Java

java -Xbootclasspath/p:c:\sqlitejdbc.jar -jar RESTSync.jar -g MyProductionRESTConfig.xml -f MyProductionRESTSync.sql

Ready to get started?

Learn more or sign up for a free trial:

CData Sync