In ReadyAPI, you can create a virtual service (virtual API) by recording HTTP or HTTPS traffic to some existing API. ReadyAPI will create virtual operations from requests and responses it detects during the recording.
You start recording in the New Virtual API wizard or the New Virtual Service dialog. This topic describes the use of the wizard.
In This Topic
Supported Virtual Services
With the wizard, you can record operations for REST virtual services only. To record SOAP services, start recording with the New Virtual Service dialog. To record JDBC virtual services, start with an empty JDBC service.
JMS virtual services cannot be created with recording.
1. Start Recording
-
From the main menu, select File > New Virtual API:
– or –
On the Dashboard, click Virtual API in the New Test tile:
-
In the subsequent New Virtual API wizard, click Recorded Traffic > Start:
-
On the next page, enter the URL of the API, you want to record requests to:
Note: The recorder uses this value to save operation paths correctly. Suppose that you send a request to http://my-serv/v2/pet/findByTags. If you enter http://my-serv/v2 as the API URL, the recorder will save the operation path as /pet/findByTags. If you enter http://my-serv, the operation path will be recorded as /v2/pet/findByTags. -
On the next page, specify the project to which the wizard will add the new virtual API. You can select from the projects opened in your current workspace. To create a new project, select <New Project>:
Click Finish to continue.
-
ReadyAPI displays a dialog, where you can select the tool for sending requests:
Depending on the target API, you can choose to open a regular web browser and send requests from there, or you can use some other tool for interaction, for example, cURL or mobile application. The latter approach, for example, helps you record traffic and create a mockup service for an Internet-of-Things API.
2. Send Requests
After you selected the tool for sending a request, ReadyAPI creates a new virtual service of the REST type and automatically runs this service. It also pre-configures the service properties to enable the recording support. We will explain the property values below.
To record traffic, send requests to your live API. The recorder will track requests and responses and will create appropriate virtual operations.
Important: In the requests you send, replace the server name with your service’s address (by default, http://localhost:8080
). For example:
A request to the live API: | http://my-server.com/v2/pet/findByTags?status=new |
Use this for recording: | http://localhost:8080/v2/pet/findByTags?status=new |
If you selected to record with a browser, you will see that the browser automatically replaces your real API URL with |
Tip: To record several responses for the same request, simply send the request several times.
3. Stop Recording
-
After you send the needed requests, stop the recording by clicking Stop on the toolbar:
-
We would recommend that you disable routing in your virtual service after the recording. Else, if you run tests against the service, it will route requests and re-record responses:
How Recording Works
The idea behind recording is rather simple: when you send a request, the virtual service redirects it to the API you specified, then receives the response and creates an appropriate operation.
To support this behavior, ReadyAPI assigns the Route and Record Non-Virted Request value to the Route Options property of your virtual service:
The Route Options property sets the functioning mode of a virtual service. The Route and Record Non-Virted Request value means that the service forwards all incoming requests to a real API and creates virtual operations for those requests, for which it does not have virtual operations yet. The real API address is set in the Route to edit field (see the image above). For information on other routing settings, see About Routing.
Notes
-
To record several responses for the same request, simply send this request several times during the recording. You can then configure response settings in the virtual service editor to use conditional responding.
-
If you request the same resource with different parameters, the service will record several operations.
-
Do not forget to disable routing after the recording is over.