Testing REST APIs is essential for web application functionality. REST APIs, based on REST architecture, support various data formats, making them widely used for flexible data transfer in web apps.
Each test case generates diverse API requests, evaluating responses to ensure accurate and secure functionality. This provides vital insights for development and maintenance.
In this article, we will create a REST API method and call it in a test case.
Log in to the Opkey portal and select the project to work on.
In the project workspace, click on Create New and select a new Service Repository to be created.
A new Service Repository is created. Rename the node and click on the Rest API Test button.
A new Service Repository file is created. Rename it and add the required URL in the Service URI section.
Based on the provided Service URI a new method is generated. Click on the dropdown to view various other methods such as GET, POST, PUT, DELETE, and PATCH available through which you can retrieve the data.
We will proceed with the GET method. Click on the Edit button to add the resource from the portal.
Here we are using the https://reqres.in/ portal.
Go to the portal and select the Get Method.
Copy the Resource and paste it in the Pop-up box.
You can now see the Resource data in the resource path . Click on the Run button.
This service will fetch the user list.
We will use the code to fetch email, first name, and last name.
Create a function library and use the "+" button to add the Service Repository you made.
Once the service repository file is added, we'll incorporate the keyword "GetValueFromJson" to extract the essential values from the resulting JSON-format output.
Click on the arrow in the Output Data section of the added service repository file. We will use the output of this step as an input for the next step.
Map the output components of "Fetch data from list" to the input data of the GetValueFromJson keyword.
For the GetValueFromJson keyword, we have to enter two arguments. Json and JsonPath. Provide the Json value as input from the first step and provide the created Json path value to the JsonPath as the first name of the first user.
With the same method, we can fetch the last name and email address of the user.
We have added three keywords here with the values and Saved the test case.
Click on the Run button and execute the test case.
Enter the details of the Session Name, Build Name, and execution agent on the Local Execution Wizard. Click on Finish.
On the live logs, View the first name, last name, and email address of the user being added.
Now let’s view the output generated.
The first keyword will generate the first name of the user.
The second keyword will generate the last name of the user.
Similarly, the last keyword will generate the email address of the user.
This is how REST API Testing works in Opkey.
Read the article on SOAP API Testing by clicking Here.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article