Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
An imitated web service runs on a server, responds to client queries, and receives requests from users. You must include virtual operations (or actions) in your virtual service in order to achieve this capability. They outline the requests that will be made for this service. You can specify one or more potential replies for each request. Depending on the test conditions, the virtual service will return either this or that response. In this article, the reader will learn about virtual services. We will also discuss how to open a project, create virtual services, add data sources to virtual services, and how to insert data into a response.
Open Project
Download project and data files
The project and data file listed below will be used in this tutorial:
To download the files to your computer, click the links above. Save the two files.
Open project
Choose the sample project file that you downloaded to your computer by choosing File > Import Packed Project from the main menu in ReadyAPI.
The service specification can be seen after you open the project:
Select Request 1 on the Navigator panel's APIs node. The request parameters are visible on the right.
As you can see, the specification only mentions the ConversionRate action. It provides the exchange rate between the two currencies that the operation parameters provide.
Create Virtual Service
Let's now incorporate a fictitious API (or fictitious service) into the app. A web service will be modeled by the virtual service. It responds to requests you send, and you can submit requests to it.
Making a virtual service involves:
Click + while pointing to the APIs (Virtual) node in the Navigator panel.
This will open the dialogue box for the New Virtual Service (see below).
To establish a virtual service using the service definition we have in the project, choose Definition > From existing API in the New Virtual Service dialogue. Then, in the dialogue that follows, choose the CurrencyConvertorSoap spec:
By doing so, the Generate Virtual Service dialogue will be opened (see below).
Select the ConversionRate action in the Generate Virtual Service dialogue box, then enter the virtual service's name, path (which will be appended to the service URL), and port information. Let's leave these fields' default settings in place and press OK to build the service:
The new virtual service will be created using ReadyAPI and made editable. On the right, you can see the service properties:
Add Data Source to Virtual Service
Let's now give our virtual service a data source.
Go to the Data Sources page in the virtual service editor. To add a new data source, click the + icon in the toolbar. Select the name of the data source in the ensuing dialogue box, then click OK:
The new data source will, by default, be of the Excel type:
Select the currency_converter_ sample.xls file you previously downloaded to your computer by clicking Browse and choosing it.
Following file selection, ReadyAPI will advise importing properties. Data source properties are the names of the columns that the data source exports in ReadyAPI terminology. Therefore, ReadyAPI advises using the Excel file's column names. Select Yes.
The following dialogue box will appear:
The worksheet for importing column names, as well as the first column's cell can both be chosen here. Keep the default settings and press OK to proceed.
The first row of the first worksheet that ReadyAPI locates in the Excel file will contain the column names. The following property names can be found on the Data Sources page:
We can now add data to the response.
Insert Data Into Responses
To enrich answers with data:
Open the Setup page in the virtual service editor.
Select the data source we created in the previous step in the Data Source section by clicking the response (which will display the response property editor on the right).
Go to the Edit section of the property editor and then select the Form tab. Select Virtual Service Response [Response 1] > Property [Rate] from the menu by clicking the ellipsis button:
We added the response body's data source property. The virtual service will now read information from the data source and insert the property value before sending the response. This is referred to as property expansion in ReadyAPI.
The service then automatically goes on to the next data source record after sending the answer. Therefore, it will read information from the Excel sheet's next row the next time it needs to provide a response. The service repeats from row one until it reaches the last row.
Frequently Asked Questions
What is the virtual service called in ready API?
It simulates replies to client requests and defines the processes that real API users will call.
What is a virtual service?
An indirect or direct provision of a real service by a virtual node through the use of a virtual router is referred to as a virtual service.
What is stub service?
Service stubs are simulations of real services that can be used in testing environments to replace them functionally.
What is mock REST API?
A mock API server or mock server API mimics a real API server by responding to requests with plausible mock API answers.