Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Creating a Virtual Service
3.
Configuring Service Responses
3.1.
Configuring a response
3.2.
Creating another response
4.
Configuring Response Dispatch
4.1.
Setting dispatch properties
5.
Running Virtual Service and Sending Requests
5.1.
Starting a virtual service
5.2.
Creating test request
5.3.
Running test request
6.
Frequently Asked Questions
6.1.
What is the ReadyAPI test runner?
6.2.
What is an analysis of test results?
6.3.
Is ReadyAPI a tool for testing?
7.
Conclusion
Last Updated: Mar 27, 2024

Your first Tutorial on Virtual Service in ready API

Author Aditi
0 upvote

Introduction

ReadyAPI is a user-friendly tool for no-code API testing intended to make your testing processes more efficient. Scale and automate your end-to-end testing for many API types. Test your functional tests against compatible load tests. Enable virtualization to give your development teams quick and dependable integrations. Agile and DevOps development teams benefit from ReadyAPI's ability to create, organize, and carry out automated functional, security, and performance tests through a single, centralized interface.

Let's dive into the article to learn more about Ready API.

ready api

Creating a Virtual Service

To build a brand-new virtual service (or virtual API):

  • File > New Virtual API can be chosen from the main menu:
Creating a Virtual Service 1
  • Select All Tests from the Dashboard New Test tile, then click Virtual API.
  • You choose how to establish operations in your virtual service in the ensuing New Virtual API dialogue box. Under REST Resources, click Start. As a result, we must manually create the operations:
Creating a Virtual Service 3
  • You can define the operations to virtualize in the following dialogue box. Leave the default GET operation type in the drop-down list selected and type /login into the edit field. Click Next button. Make sure the operation name is preceded by a slash (/):
  • You can choose the project to which the new virtual service will be attached at this point. Keep the default selection for the drop-down list's "New Project" option, then click "Finish":
  • The virtual service will be added to a new project that ReadyAPI will construct. It will then ask you what steps you want to take next:
Creating a Virtual Service 6

ReadyAPI launches the virtual service editor:

virtual service editor

The functionality of the virtual service will be configured, and the response contents will be specified in the following tutorial step.

Configuring Service Responses

You can set up different features of service mocking in the virtual service editor. You can add, remove, and configure answers for activities on the Setup page, which is the default active page. You can provide one or many solutions for each action. One of these responses will be sent back by the virtual service. The Dispatch settings are used to indicate which response it should return. In the next phase, we will collaborate with them. Let's now build responses for the GET /login request.

Configuring Service Responses

Configuring a response

When we established an operation in the New Virtual API dialogue, ReadyAPI produced one answer. The response is empty by default. Let's set it up:

  • Click the editor's response. On the right, you can view the response properties:
  • Click the response name. Enter LoginSuccess in the following dialogue box, then click OK.
  • Set the following property values in the Edit section:
HTTP Status Code: 200-OK
Content/ Media Content: application/JSON
Editor:
{
"access_token" : "1/fFAGRNJru1FTz708zhT3Zg",
"expires_in" : 3920,
"token_type" : "Bearer"
}
  • Leave other properties' default settings alone.

Creating another response

  • To add another response to the action, click Add Response. When responding, indicate LoginFailed:
  • HTTP status code: 400 - Bad Request should be entered. 

Responses to services have been configured. We must specify the circumstances under which a specific response will be sent. We must first define the Dispatch setting in the following step.

Configuring Response Dispatch

The Dispatch Style setting determines a virtual service's reaction to an incoming request. Every virtual operation can choose from various dispatch mechanisms provided by ReadyAPI. A dispatch style can be selected in the virtual service editor:

Dispatch style Sequence is the default for new operations. The results of an operation will be returned in a set of sequential responses you define for it. Depending on the content of the request, you can choose a response using the Query Match and XPath styles. The Parameter style will enable you to modify the answer by the incoming request's parameter values.

Setting dispatch properties

  • Choose Parameter from the Dispatch Style drop-down selection for the Get /login virtual action, then click Configure.
  • Set LoginFailed as the default response.
  • Click to add a new rule. The Rule Editor will then be activated.
  • The following values are set:
    • Select the dispatch style and click Configure.
    • Select the default response.
    • Click Add icon to add a dispatching rule.
    • Specify the condition on the Rule Letter and choose the desired response.

The dispatch settings are set up. Our virtual service is now prepared for testing and running.

Running Virtual Service and Sending Requests

The dispatch settings are set up. Our virtual service is now prepared for testing and running.

Starting a virtual service

You can use other computers in your network or your computer to run virtual services. You must install VirtServer on different computers for it to function.

Let's launch the virtual service on your PC for this tutorial. Click Run in the service editor to accomplish this.

Creating test request

We can send queries to your virtual service after it has started.

  • Copy the value of the Virtual service URL box after selecting the virtual service in the Navigator panel to display its properties:
Creating test request
  • In the Navigator panel, expand the APIs node. When you introduced an operation to your virtual service, ReadyAPI immediately created an API definition for your virtual service and included the process to that specification:
Creating test request 1
  • Open the request editor, and then enter the endpoint that your virtual service uses:
  • We must now define the request parameters. Click and enter information in the table to do this. 

Running test request

  • In the request editor, select Send Request to simulate a request. The service will handle the request. In the editor, you can view the contents of the LoginSuccess response.
  • Rerun the request after changing the client id parameter to a different value. The virtual service dispatcher will select the response LoginFailed:
Running test request 2
  • Go to the Transaction Log page of the virtual service editor after selecting your virtual service in the Navigator panel.
    • Select the virtual service from navigator.
    • Click on Transaction Log page.
    • Select a request or response.
  • The request-response pair for each row on the page represents a transaction.
  • Select the request or answer you want to see the contents of from the list on the page. The contents are shown on the right.
  • Stop the virtual service once you've sent queries and seen results.

Frequently Asked Questions

What is the ReadyAPI test runner?

You can run functional tests with the test runner and export the results. Either the ReadyAPI user interface or the command line can launch the runner. When you need to build the command line and check the settings, the latter strategy is helpful.

What is an analysis of test results?

Analysis of performance test results. In contrast to scripting and execution, performance test result analysis is the most crucial and technically complex aspect of performance testing. To complete the test result analysis phase and wrap up the testing, a performance tester needs to use his basic skills.

Is ReadyAPI a tool for testing?

A tool for REST and SOAP API automation testing is called ReadyAPI. ReadyAPI focuses on boosting efficiency and usability when used to test web services. You can simplify thorough web services testing with ReadyAPI.

Conclusion

In this article, we have extensively discussed the virtual service in ready API. We have also explained how to create a Virtual Service, ways for configuring Service Responses, configuring Response Dispatch, running Virtual Service and Sending Requests, and more in detail.

We hope this blog has helped you enhance your Ready API knowledge. To learn more, check out our articles on introduction to API and its usageWeb API introduction, and real-world API. Practice makes a man perfect. To practice and improve yourself in the interview, you can check out Top 100 SQL problemsInterview experienceCoding interview questions, and the Ultimate guide path for interviews.

Do upvote our blog to help other ninjas grow. Happy Coding!

thank you image
Live masterclass