Jmeter Tutorial: Testing REST Web Services

In this Jmeter Tutorial, we look at how we can test a REST API or Web Service using Jmeter tool.

We can use Jmeter to send Json request to a RESTful Web Service and also parse the Json response.

Test Plan for REST Web Service

  • Thread Group
  • HTTP Request

Like with any Jmeter tests, we first need to create a Thread Group along with a HTTP Request Sampler.

testing-rest-jmeter-1

If you now run the test, you may get an error with a response code of 415 and a response message “Unsupported Media Type”.

This is because the REST API might expects “Content-Type” and “Access” parameters in the header request.

 

testing-rest-jmeter-7

  • HTTP Header Manager

Next we need to add a HTTP Header Manager to send parameters in the header of the request. We need to send “Content-Type” and “Access” variables as request headers.

testing-rest-jmeter-3

 

testing-rest-jmeter-4

Most probably, you need to register your application via an API key. This needs to be sent as a POST method to the REST API in the body of the request.

  • POST data in the Body of Request

testing-rest-jmeter-8

 

And the response in Json format

testing-rest-jmeter-9

Next is to extract or parse the Json Response.

  • Extract Json Response

Jmeter has a handy plugin called JsonPath which can be used to parse Json responses. This plugin is in the Extras with Libs Set.

Once you have installed the above plugin, we can use the Json Path Extractor as a post processor

testing-json-path-extractor

Once we have added Json Path Extractor to our test plan, we can use the dot notation to reference the Json elements.

In this example, we want to extract the value of the “client_id”:

json-path-extractor

The value of the “client_id” will be saved in the variable named “client_id_value”. You can give any meaningful name you wish.

Once the value is saved in the variable name, we can recall the value by using that variable name in the format ${client_id_value}

jmeter-rest-testing

2 Replies to “Jmeter Tutorial: Testing REST Web Services”

  1. This information is very good, helping a lot. I am facing below issue, please help.
    I need to pass a data from a json response to the subsequent request’s Post Body data however it is not working, something is going wrong.

    First request returns the JSON in response body which looks like this:

    “accessToken”:[{“idToken”:”eyJ05C3RU”,”token”:”159c82d30ec3123e873ab989cc”}] 0000000 I have to extract ‘accessToken’ value to pass it to the next request’s post bodydata (not under parameter tab of the request, it has to pass to BodyData tab of the next request)

    I have created to JSON path extractors for the first request where getting response data with these values. 1JSON path extractor: $..accessToken[0].idToken

    passed this in json path expression:$..accessToken[0].idToken

    in the request of next request: {
    “idtoken”: ${idToken}
    }

    view results in tree: shows post data as request: POST data:{
    “idtoken”: ${idToken}
    }

    response data: omething broke!SyntaxError: Unexpected token $ at Object.parse (native)

    Please help to resolve the issue. it will be really helpful.

Leave a Reply