What is an API?
API (Application Programming Interface) is an intermediate service that makes the interaction between two applications possible.
It’s a messenger that takes a request from one system to another system, provides the requirements to another system, and gets the response back to the requesting system.
REST API
REST stands for Representational State Transfer. It is an architectural style for building an application program interface that uses HTTP requests to access and use data. The data can be used to GET, PUT, POST and DELETE data types, which refers to the reading, updating, creating and deleting of operations concerning resources.
SoapUI API
SOAP stands for Simple Objects Access Protocol. Soap is a standard communication protocol system that permits processes using different operating systems, such as Linux and Windows, to communicate via HTTP and its XML. SOAP based APIs are designed to create, update, recover and delete records.
Why choose Apache JMeter for API Testing?
Below are the reasons why Apache JMeter is used for API Testing:
- Apache JMeter is an open-source Java-based tool used to perform load and performance testing.
- Since JMeter is solely based on Java, it can be configured in any platform that has a JVM, such as Windows, Linux, or macOS.
- Testing Json APIs with JMeter is very easy.
JMeter API Testing
In order to perform API testing in JMeter, you have to download and launch the JMeter application in your system. Below are the steps for downloading and installing JMeter.
JMeter Installation and Setup
JMeter is a framework for Java, so the very first requirement is to have JDK installed on your system.
Step 1: Verify Java Installation
Firstly, verify whether you have Java installed on your system. Open the command prompt and execute the following command to check if Java is installed or not.
C:\> java -version
If Java is not installed, then install it first.
Step 2: Set Java Environment
Set the JAVA_HOME environment variable to point to the base directory location, where Java is installed on your system. For example −
Set the environment variable JAVA_HOME to C:\Program Files\Java\jdk1.8.0_191
Then, append the Java compiler location to System Path –
Append the string; C:\Program Files\Java\jdk1.8.0_191\bin to the end of the system variable Path.
Step 3: Download JMeter
Download the latest version of JMeter from here – https://jmeter.apache.org/download_jmeter.cgi. Download apache-jmeter-5.3 and copy it into the C:\>JMeter folder.
Step 4: Run JMeter
After downloading JMeter, go to the bin directory. Now click on jmeter.bat
Steps to Perform API Testing in JMeter
This is how you can test REST APIs using JMeter.
- First, start your JMeter and select the Test Plan.
- Right click on the Test Plan, click on Add, and add the Thread Group.
- Then, add the HTTP Request, enter the server name or the IP of the API, and set the Path and Parameters.
- Right click on Thread Group, select Sampler, and add the HTTP Request.
- Once you have the API, find out the HTTP request method, server name, path, and parameters. Then, select the HTTP request method and copy the values corresponding to the server name, path, and parameters in the HTTP Request of the JMeter Test Plan.
- Now, add a Listener to view the results of the test. Right click on HTTP Request, select Listeners, and add View Result Tree / View Result in Table.
- Now, all you have to do is run your Test Plan. You can increase the number of Threads.
- Test results will show the request and response for the HTTP Request.
- If you get the Status response code as 200, it means that your API has passed the test and is working fine.
Now, you have successfully tested your API.