How to handle Path Parameters in Rest Assured? (Updated 2020)

This entry is part 14 of 14 in the series Rest Assured Tutorial

So far, we have already covered several major HTTP method operations using REST-Assured. If you haven’t gone through that, please check this link. Now, In this tutorial, we will see “How to pass/handle Path Parameters in Rest Assured using pathParam?”.

 

 

Simple representation of handling Path Parameter using RESTAssured...!!! Click To Tweet

In this tutorial, we are going to cover the below topics:

  1. What is Path Parameter?
  2. How to pass the Path Parameter with the Request in Rest Assured?

 

Let’s begin:

1. What is Path Parameter?

‘Path Parameter’ is basically used to identify a specific resource or resources.

For example, In case, if we need to identify an employee based on his/her ‘id’, we are going to use ‘pathParam’.

GET /employee/{id}

Sometimes there is a confusion between URI Parameter (or Path Parameter) and Query Parameter. ‘Query Parameter’ is used to filter or sort the resources.

For example, In case, if we need to filter out the employees based on their class, we are going to use ‘queryParam’.

GET /employees?class=9

 

2. How to pass the Path Parameter in Rest Assured?

In this tutorial, we will test the ‘Dummy Sample Rest API’ which is available here. This page contains Fake Online REST API for the testing purpose which is performing various CRUD operations.

Let’s take an example of one of the API GET endpoints available at the above-mentioned website which is ‘/employee/{id}’ where the full-service URL with an endpoint is ‘http://dummy.restapiexample.com/api/v1/employee/{id}‘. It’s a simple GET request and we are trying to access the details about the employee whose id is 16914 which we are passing through ‘pathParam’ as part of the request in this below example:

Here is the code to send the request with Path Parameters to the above-mentioned Service Endpoint:

 

Eclipse Console Output:  

 

That’s it, it’s that simple to handle Path Parameters in REST Assured API: ?

 

Simple representation of handling Path Parameter using RESTAssured...!!! Click To Tweet

If you like this post, please check out my other useful blog posts on Rest Assured:

Other Useful References:

Series Navigation<< How to Parse JSON Response with REST-assured

Leave a Reply

Your email address will not be published.Required fields are marked *

Facebook Twitter Instagram YouTube

Apach_HttpClient_Tutorial_Popup_Techndeck