Step-by-Step Guide to Perform JMeter API Testing

The QA team tests APIs to validate the application core on the server-side, and  doing this activity manually takes time. JMeter API Testing comes into play here. In this tutorial, you will understand all that is needed to perform API Testing using JMeter.

Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN StackExplore Program
Want a Top Software Development Job? Start Here!

What Is an API?

API or Application Programming Interface is an intermediate software that makes the interaction between two applications possible. To understand this even better, let's take an example.

For example, If you are booking a flight, you begin the process by searching online for flights that match your destination, departure, return dates, and many other related filters. To make a decision that considers all these choices, you interact with the airline's website and access their database. You need to see if any seats are available on those dates and what the costs might be for them. This entire process that you undergo, from the time you begin to the time you finish, is facilitated by an API.

API_Application

Every time you use an application on your mobile phone, send a message or check the weather on the phone, you are using an API.

These APIs are tested to check the functionality, performance, readability, and security of any programming interface. One of the most popular and simple tools to perform API Testing is the Apache JMeter.

JMeter_Logo.

Why Choose Apache JMeter for API Testing?

Some of the prominent reasons as to why Apache JMeter is used for API Testing are:

  • Open-source tool - The Apache JMeter is an open-source tool based on Java used to perform load testing and performance testing.
  • Cross-platform testing - Since JMeter is solely Java-based, it can be used on any platform that has a JVM; Windows, Linux, or macOS. 
  • Smooth API Testing - API Testing enables easy, smooth, and rapid API testing.

JMeter_API_Testing

  • Quick scope tests - JMeter is a potent tool for performance testing, making the process easy for everyone, whether experienced or inexperienced.
  • Enables load testing - JMeter is a very effective tool to measure if a web application satisfies a particular load requirement or not.
  • Enables stress testing - JMeter can simulate users to measure the application performance under a lot of stress.
  • Lots of plugins - JMeter offers a lot of plugins, and more plugins can be installed easily by installing a Plugins Manager.

Now, let’s see the process of performing JMeter API testing.

Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN StackExplore Program
Want a Top Software Development Job? Start Here!

Demo: JMeter API Testing

To download JMeter, you will need to access the Apache JMeter website and download the file. To know the entire download and installation process for JMeter, you can check this JMeter Download and installation video

The first step is to set up the Apache JMeter, as shown below.

  • Go to the Apache JMeter folder → bin folder → open the batch file.

Batch_File

This might take a while. Wait till the JMeter window opens on the screen.

It divides the home window into two sections: the left side has all the test plan elements, and on the right side, all the configurations of that element are added. 

As you are on the test plan element, you can see the configurations of the same.

  • Right-click on the test plan
  • Select the add option
  • Then in the menu that appears, select the threads option and then thread groups

Here, the number of threads refers to the number of users. The ramp-up period in seconds option states the time gap between the users' hits. There is a loop count where you can choose how many times the test will run for the number of users, and also, you can select the test to run infinite times. 

There is also a scheduler here to help you schedule the test start-time and end-time.

For the purpose of this tutorial, let's set everything to one.

Now, select some sample APIs, as given below;

  • Go to your browser 
  • Search for “some sample rest API for testing”
  • Open the first link “reqres.in”

Let’s create and run GET, POST, PUT, and DELETE Rest API requests in JMeter in the demo. 

Master Core Java 8 Concepts, Java Servlet & More!

Java Certification TrainingENROLL NOW
Master Core Java 8 Concepts, Java Servlet & More!

Here, in this link, you can GET, POST, PUT, and DELETE Rest APIs.

Sample_API_Links

So, choose the first link: List Users. 

  • Here, click on the request link
  • Open the link that appears in the new tab
  • Identify the URL for this API
  • Copy this URL and open the JMeter window

Then in the JMeter window, do the following:

  •  Right-click on the Thread group
  • Navigate to “add”
  • In the box that appears, select “samplers”

You can see the types of requests that JMeter can work on

  • Choose the HTTP request. 

Here, you will have to give the address to some home pages or websites

  • In the Server Name or IP box, give the paste the GET API request URL 
  • In the Protocol box, put "HTTPS"

If the URL in the protocol was HTTP, this box would have been left empty. In the URL, put the URL link; remember not to put any slashes in the IP Address. Also, anything after the URL should be put in the path.

  • Now, put the path from the URL in the path box

Next, you must take part of the URL, beginning with the “question mark” and use it to assign the parameters. This is required since it is the GET API type.

  • Add the name in the parameters
  • Give the name as page and value as 2
  •  Name this HTTP Request as GetAPI

GetAPI_Testing.

Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN StackExplore Program
Want a Top Software Development Job? Start Here!

After this HTTP request is ready, perform the test on it. To determine what the results of the test will be, add some listeners.

  • Right-click on the Thread group
  • Go to listener options
  • In the box, check the different types of reports that JMeter provides
  • For now, Select two "view results tree" and “view results in table"
  • Then save the test and run it

Simply click on the green button to run the test.

After running the test, it's time to check the results:

  • Go to the "view results tree"

The green status shows that the test was successful. 

  • Then go “view results in a table”

The green status again shows the test was successful. 

Since the number of threads and loop was denoted as one - both at the entry in both the results, the test result has come out accordingly.

Now, try one more thing:

  • Go to the thread group 
  • Change the number of threads to be 10
  • Run the test

After running the test, check the "results in the table" and see the testing being performed. This can be seen in case "view results in the table" is available too.

In the view results tree, you can click on a request and see different information. Here you can see the sample start, load time, latency error, etc. In the "view results in table," window, you will be able to see all the information in a tabular format.

Listeners_GET_API.

You can also see the response data in the above image. This is the same data available when you copied the URL from the browser. Furthermore, the response headers and the request placed can also be checked. 

Dive Deep Into Java Core Concepts

Java Certification TrainingENROLL NOW
Dive Deep Into Java Core Concepts

Now, when you are done with the GET API request, let's add the second request that is the POST request.

  • Add an HTTP request again by going to the sampler in the thread group
  • Come back to the browser window
  • Click on the POST API option 
  • Open the request URL in a new window
  • Go to this window and copy the URL
  • Come back to the JMeter window
  • Rename this HTTP request as Post API 
  • Then paste the URL in the server name or IP box 
  • Place HTTP in the protocol box, address in the Server or IP address box, and path in the path box
  • And in the HTTP Request drop-down, select the POST option this time
  • Navigate to the parameter part
  • Here, select the body data option and add body 

For adding the body:

  • Go back to the browser window
  • Copy the body from here
  • Come back to the JMeter window
  • Paste the body here

POST_API.

Now, when the test is all set it’s time to check the output.

  • Go to the two listeners and clear the previous output
  • Then save the test and run it
  • Now you can see the two tests since the thread count is one

Making the thread count 10 again, you can see the test running a required number of times, 20 times. Furthermore, the information about different requests that include other parameters like latency, errors, etc., can be accessed.

Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN StackExplore Program
Want a Top Software Development Job? Start Here!

Now, let's move on to the third API request, the PUT request.

  • Go back to the browser
  • Click on the PUT request
  • Open the requests in the new tab
  • Copy the URL
  • Come back to the JMeter window
  • Make a new HTTP request like the previous two times
  • Rename this HTTP request as Put API
  • Paste the URL in the server name or IP box 
  • Put HTTP in the protocol box, address in the Server or IP address box, and path in the path box 
  • And in this HTTP Request drop-down, select the PUT option this time

Here too, you will have to add body data. 

  • Go back to the browser window
  • Copy the body from here
  • Coming back to the JMeter window, select the body data option and paste the body here

PUT_API

Now, after it sets the test, run the test in the case of the previous two APIs.

  • Go to the two listeners and clear the previous output 
  • Make the thread count as one
  • Save the test and run it

Again make the thread count as 10 and see what happens.

  • You can see the test running a required number of times
  • And a lot of information can be checked again, as in the previous cases

Prepare Yourself to Answer All Questions!

Automation Testing Masters ProgramExplore Program
Prepare Yourself to Answer All Questions!

Now, let's add the last API request that is the DELETE request.

  • Go back to the browser
  • Click on the DELETE request
  • Open the requests in the new tab 
  • Copy the URL
  • Come back to the JMeter window
  • Make a new HTTP request
  • Rename this HTTP request as Delete API 
  • Paste the URL in the server name or IP box 
  • Put HTTP in the protocol box, address in the Server or IP address box, and path in the path box
  • And in this HTTP Request drop-down, select the Delete option this time

DELETE_API

Here you do not have to add anything in the parameters section. 

  • So, go to the two listeners and clear the existing information
  • Save the test and run it

Since the number of threads was not 1 this time, the test can be seen running the required number of times. You can see the information for any API request by clicking on it.

Listeners_All_the_API

So, this is how you can create, run and perform API Testing for different API requests in JMeter.

Advance Your MERN Stack Career in 6 Months!

Full Stack Developer - MERN StackEXPLORE COURSE
Advance Your MERN Stack Career in 6 Months!

Conclusion

By now, you would have understood everything you need to know about JMeter API Testing. In the beginning, you learned what an API is, and then you saw why JMeter is chosen to perform API Testing. Then finally, you understood the process of performing API Testing using JMeter with a hands-on demo. Check out our Java Certification Training to know more about Jmeter Testing.

To know more about JMeter API Testing, you can have a look at this video.

Are you looking to build a career in software testing? check out Simplilearn’s Full Stack Developer - MERN Stack and Automation Testing Masters

If you have any questions for us, let us know in the comments section of the tutorial, we shall have our experts answer them for you.

Happy learning!

About the Author

Ishan GabaIshan Gaba

Ishan Gaba is a Research Analyst at Simplilearn. He is proficient in Java Programming, Data Structures, and Project Management. Graduated in Information Technology, Ishan is also passionate about writing and traveling.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, OPM3 and the PMI ATP seal are the registered marks of the Project Management Institute, Inc.