Data Sources in Virtual Services

Applies to ReadyAPI 3.56, last modified on October 29, 2024

About

A common task for a virtual API is to provide responses that have the same structure, but different data. For instance, your virtual service may return different temperature values for different places specified by parameters of incoming requests.

To solve this task, you may want to decouple the response structure from data and store the content outside of your service, for example, in some file or database. In ReadyAPI, virtual services support loading data from external data sources like Excel sheets, CSV files or database tables and inserting this data into the responses. This feature also allows you to create services that share the same set of data for their responses of different types. This section describes how you can configure and use data sources in your virtual services.

Note: Data sources are a Pro feature. To use them in virtual services, you need ReadyAPI Virtualization license. If you do not have it, you can request it on our web site or start a trial.

How It Works

To understand how a data source works, imagine a simple table with data. Columns of this table would refer to a property, for example “Temperature” or “City”. And each row would be a record with a set of possible values of these properties: different cities and related temperature values.

  1. When you start a virtual service that uses a data source, the service connects to the data source and positions the data cursor to the first record:

    How data source works in ReadyAPI ReadyAPI Virtualization: Sample data
  2. When the virtual service receives a request, it selects a response according to the dispatch settings and runs script event handlers. At that, the service can retrieve data from the current data record and insert this data into the response. During all these actions, the data cursor points to the same record of the data source:

    How data source works in ReadyAPI ReadyAPI Virtualization: Incoming request

    After sending the response, the virtual service forwards the cursor to the next record. Note that the service forwards the cursor even if the selected response does not retrieve data from the data source:

    How data source works in ReadyAPI ReadyAPI Virtualization: Sending response
  3. When the virtual service reaches the last record of a data source, it jumps to the first record.

Supported Data Sources

Virtual services use the following data source types. Find information on data source settings by the links below:

Data Source Type Description
Excel A worksheet in an Excel workbook.
File A file with comma-separated values.
Grid An arbitrary table which you create on the Data Sources page and to which you enter data manually. The data source properties you create on the Data Sources page are columns of this table.
JDBC A table, view, query, or stored procedure of some database, to which you connect through JDBC.
Data Connection A table, view, query, or stored procedure of some database, with which you work through a predefined JDBC connection created in the Databases wizard.
Data Generator This data source produces test data for the properties you created on the Data Sources page.

Quick start guide

These steps help you quickly set up a data source in a virtual service. For details on configuring data sources, see Configure Data Sources in Virtual Services.

1. Configure data source

Data sources in ReadyAPI Virtualization: Quick start guide

Click the image to enlarge it.

  1. Open the Data Source page:

  2. Click to create a new data source and select the needed data source type.

  3. Create properties.

  4. Configure the data source. The needed settings depend on the selected data source type. See Data Source Types.

2. Insert data source values into response

Data sources in ReadyAPI Virtualization: Insert data source value

Click the image to enlarge it.

  1. Switch to the Setup page and open a response.

  2. Expand the Data Source section and select the needed data source from the drop-down list.

  3. Expand the Edit section. Use the Get Data context menu item to select the property of the data source.

To learn more, see Refer to Data in Responses.

See Also

Configuring Virtual Services

Highlight search results