Creating Requests
Adding requests to a virtual API can be different for REST, SOAP, JMS and JDBC virtual services. Here are some methods to create requests:
Create Requests from Toolbar
- To open the virtual service editor, select your virtual service from the panel on the left.
- Click on the desired virtual service in the virtual service editor:
- JMS route (JMS virtual service)
- Operation (SOAP virtual service)
- Action (REST virtual service)
3. After selecting the virtual service type, the dialogue box opens, where you can specify the properties of the new request.
Adding from Specification
This method can be used for REST and SOAP only.
If you have a Swagger, OpenAPI, WSDL, or WADL specification added to your ReadyAPI project, you can create virtual requests directly through that specification following the steps below:
- Select Generate Virtual Service from the Navigator panel on the left.
- In the dialogue that opens:
- Select the operations that are to be added to the service
- Select Add to existing virtual service
- Choose your required virtual service in the drop-down list, Virtual Service
- Click OK
Using Existing Operations
Valid for REST, JMS and JDBC only.
Clone the existing operations using previously defined operations as the base. This is time effective and quick. Follow the steps below:
- In the virtual service editor, click Duplicate VirtAction after finding the desired base operation. This new operation is added to the end of the operation list.
- From the list, select the operation name, and change the resource path in the editor on the right. I the resource path is kept, you will have two virtual operations for the same resource. The virtual service will use the operation it finds earlier in the list.
Recording Requests
This is used for REST, SOAP and JDBC only.
If you want to add requests based on a real API, you need to configure your virtual service to record non-virt operations and use recordings.
Creating Responses
We will now learn how to create responses for virtual requests on a virtual API.
Add Responses
One request may have multiple responses. To virtualise an API, responses must be created to handle virtual requests. The dispatch settings are used to select a response for the reply.
Click add response to create a response for the desired request in the virtual service editor. ReadyAPI creates an empty response.
Set Contents of Response
Contents of the response need to be added after the creation of the response. The contents and editor information depend on the virtual service type: REST, JMS, and SOAP use different response properties:
- HTTP status code field is set for REST and SOAP services. This specifies the code that will be returned to the client, which is used to determine if the request was successful.
- For JMS services, response contents are specified in the Edit fields.
- Results section is used to specify the contents of the JDBC virtual services. The number of queries modified is displayed in the section.
Set Custom Headers
Custom headers can be set to responses in the Headers section. These custom headers can include data of the data source and visual service properties.