How To Do API Testing with JMeter

Create a basic JMeter API test script.

Table of Contents

Introduction

Application Programming Interface is a very popular term among developers. It is simply a request provider that responds to your request. In other words, it is an intermediate that allows communication between two applications. Google Maps, Twitter, Amazon S3, Weather API are some popular APIs in the industry.

The two widely used Web services are SOAP and API. In this tutorial, you will be learning to use the  REST API with Apache JMeter. Also, you will be able to check their performance with your test parameters.

REST API

Representational State Transfer API is a collection of architectural principles. It has a simple interface that can manipulate and identify the resource easily within the request. We are using Weather API for this tutorial.

Sign up to Weather API in order to get your API key with this link. Your API will be received through email, after the verification of the account. Let’s create a REST API request using JMeter to get the weather data of London, UK with HTTP Request Sampler.

Add HTTP Request Sampler

1
Step 1: Create a Thread Group.

blank

I have named it as API Testing. Leave the rest of the settings as it is for now.

2
Step 2: Create an HTTP Request

blank

Create an HTTP Request by following these steps. Right-click on the Thread Group name and click Add > Sampler > HTTP Request.

3
Step 3: Navigate to ‘OpenWeather’ site

blank

We are using the Current Weather Data API to get current weather data of a certain location. Go to the API page in the Weather API and click “API doc” under the “Current Weather Data” API.

4
Step 4: Get the API call details.

Get the API call under the “By City Name” Section. Select the first one with the City Name. You can check your city name by searching in the UI search bar of the website. If the name is spelled correctly it will show the weather details as below.

api.openweathermap.org/data/2.5/weather?q={city name}&appid={your api key}

Let’s examine each part of the API call.

“api.openweathermap.org”: IP of the web service.
“/data/2.5/weather”: Path of the web service.
“q”: City Name which you like to get the weather data.London in my case.
“appid”: Your API Key.

5
Step 5: Fill-in required fields and set ‘Method’.

blank

Complete the required fields in the HTTP Request sampler. Fill the IP and Path with the details above. Select the “Method” as a “Get” Method

6
Step 6: Fill-in the API Key parameters.

blank

Add City Name and API Key as parameters in the Parameter section. Click the Add button to insert the parameters. Name is the parameter name and value is the parameter value. Check the image below to insert it correctly. I have added “London” to my city.

Run and Validate

7
Step 7: Add a listner to view response.

blank

You have to add a listener to see the response from the server. Right-click on the thread name and click Add > Listener > View Results Tree to add Results Tree Listener.

8
Step 8: Run your script.

blank

Run your script by clicking the “Start” button on the menu bar and observe the results in the “View Results Tree Listener”.

9
Step 9: View the response data.

blank

View received weather data from the “Response Data” section. You can see the weather data in London as requested above.

10
Step 10: Increase load for re-run.

blank

Increase the load to the API and test the results. Go to Thread Group and Increase the “Number of threads” to 15.

11
Step11: Clear results and Re-Run new load.

blank

Clear the previous results in the listener by “Clear all” button in the menu bar and re-run the test by “Start” button. You can see the server response to the load that applied. It is responding well. Increase the other thread properties and check the responses as you needed.

Now you can Test an API using Apache JMeter.Use some other web services APIs and test the results. You can check the performance of your API services in that way. Cheers.

Tushar Sharma
Tushar Sharmahttps://www.automationdojos.com
Hi! This is Tushar, the author of 'Automation Dojos'. A passionate IT professional with a big appetite for learning, I enjoy technical content creation and curation. Hope you are having a good time! Don't forget to subscribe and stay in touch. Wishing you happy learning!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

RELATED POSTS

How To Create FTP Test Plan in JMeter

About File Transfer Protocol File Transfer Protocol is a widely used standard network protocol for FIle sharing between a client and server in the same...

How To Do Database Testing with JMeter

Introduction In this 'How-To', You will be guided to perform a database load test using JMeter. We will be installing Apache JMeter to perform the...

Â

RECENT 'HOW-TO'

How To Install Oh-My-Posh On Windows PowerShell

Oh-My-Posh is a powerful custom prompt engine for any shell that has the ability to adjust the prompt string with a function or variable. It does not...

MORE ON CODEX

FEATURED PROJECTS

Windows JDK Manager (win-jdk-Manager)

ADjo LABS PROJECT : Simple and lightweight desktop utility with Interactive cmd Interface for easy view, re-point and switching between JAVA versions on windows. Demonstrating the capability...

MORE IN THIS CATEGORY

How To Add SSH Private Keys to Eclipse

One of the common use cases for accessing Git repositories on Github is authentication via SSH keys. This offers a secure way of working...

How To Install WordPress Locally using XAMPP

1. Introduction Installing WordPress on your computer helps you try out WordPress, test themes and plugins, and learn WordPress development.  It lets you operate a...

How To Convert List To Array in Java

A common scenario faced by programmers is to convert a Java List to an Array. A 'List' is part of the Collection Framework and...

How To Find Broken Links with Selenium

What is a broken link? Links are used for navigating between webpages. Users are directed to a web page when they click or type a...

CHECKOUT TUTORIALS

Java Tutorial #6 – Jump Statements

Introduction The break statement is used to stop further execution. It can be used either in a loop or within a switch statement. Break Statement The break...
- Advertisement -spot_img