Application Programming Interface is a layer between the User Interface and Database Layer. It enables thorough correspondence and data sharing between the two frameworks. Programming interface testing is a product testing practice that tests APIs, whether they meet requirements for quality, execution, and security. The programming interface indicates how the program ought to collaborate with other programs.
Example: At a restaurant, you order your meal depending on the options available on the menu. A server in the café records your request and conveys it to the kitchen to instantiate work on your order. When the order is prepared, the server gets your food from the kitchen and serves it to you at your table.
In this situation, the server's job resembles that of an API. Like a server, the API takes a solicitation from a source, takes that solicitation to the database, gets the mentioned information from the database, and returns a reaction to the source.
Why API Testing?
Most organizations are pushing toward a microservices model for their applications. This implies that various segments of their applications can have separate datastores and separate directions to associate with that datastore.
Besides, API testing enables the analyzer to discover bugs prior to the development procedure, often before the UI has been made. Furthermore, API testing enables the analyzer to make demands that probably will not be permitted through the UI, which is essential for uncovering potential security imperfections in an application.
What is Postman?
Postman is presently one of the most common tools used in API testing. It was started in 2012 as a side project by Abhinav Asthana to simplify API workflow in testing and development.
We can set the Global Variables both manually as well as by code. Both methods are best for quick results. Let us first look at how we can create the Global Variable by a code:
Set the Global Variable with a Code:
We can add a global variable through the following code:
Set a variable name in “Variable_key” and enter a value in “Variable_value”. Refer to the screenshot below:
Step 1: Make a new request and enter the request URL.
Step 2: Navigate to the Pre-request Script.
Step 3: Type the referenced command to create the global variable and select the Send button.
Step 4: Click on Environment quick look icon.
Step 5: Ensure that the desired global variable is created.
Now, let us explore how we can create the Global Variable manually!
Set the Global Variable Manually:
Step 1: Make a new request, enter the request URL and click on Environment quick look icon.
Step 2: Explore and click on the Global edit button.
Step 3: The Postman will open a new window with all Global Variables. You need to include the variable name in it.
Step 4: Add the variable initial value; it will automatically initialize the current value to be the same as the entered value.
Step 5: Click on the Save button to successfully add the global variable.
Additionally, we can also get the global variable value by using the following code:
[pm.globals.get("variable_key");] put global variable name under variable_key, user will get variable after following steps:
Step 1: Create a new request, enter the request URL, and paste the mentioned code over the tests section.
Step 2: Click on the send button.
Step 3: Click on the console icon on the bottom left of your screen to open the Postman Console.
Step 4: You will get the value of the desired variable.
Removing Global Variables:
Global Variables can be expelled both manually and by code. I will be demonstrating the code option first:
Removing the Global Variables with a Code:
We can evacuate a global variable using the following code:
Put the global variable name under variable_key; the system will remove the variable after the following steps:
Step 1: Make a new request and enter the request URL. Put the piece of referenced code under the tests.
Step 2: Navigate to the environment quick look icon and click it.
Step 3: Check and ensure that all Global Variables are accessible.
Step 4: Click on the send button.
Step 5: For verification purposes, click on the Environment quick look icon.
Step 6: Verify that the desired global variable is removed.
Removing Global Variables manually:
We can expel global variables through the following manual steps:
Step 1: Make a new request, put in the request URL, and then click on the Environment quick look icon.
Step 2: Navigate to the Global edit button and click it.
Step 3: The system will open another window with all the Global Variables. Navigate to the specific variable that you want to remove.
Step 4: The system will now show a cross icon, click on it.
Step 5: Click on the Save button. The Global Variable is now expelled!
I hope that this blog has brought clarity to your concepts of API Testing and Postman tool. If you have any insights, questions, or queries, feel free to leave a comment below. We will get back to you!
If you have any question or queries, do not hesitate to reach out to us!