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 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...

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...

Â

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

SEPA Bulk File Generator and Validator

ADjo LABS PROJECT: SEPA Bulk File Generator and Validator. Supported File Types PAIN008, PAIN001, PACS003 and PACS008. Tested for supporting PAIN.008.001.001 and PAIN.008.001.002 (version 1&2). The XML...

MORE IN THIS CATEGORY

Getting Started with Apache JMeter

1. Introduction As a developer, you may have tested the functionality of your code hundreds of times during development. This is known as functional testing....

How To Change Font for Eclipse Editor Pane

This article shows how to change the text size and style for the Eclipse editor pane. The font used for Eclipse editor pane can be...

How To Create Singleton Class in Java

Design patterns Overview Design patterns are basically solutions to programming problems that developers normally encounter during software development. Design patterns were first documented by four...

How To Change Font for Eclipse Package Explorer

This article shows how to change the Package Explorer text size and style. The font used for tree and table views can now be customized...

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...

Working with JMeter Listeners

- Advertisement -spot_img