In this tutorial, we will learn “How to pass/handle Path Parameters in Rest Assured using pathParam?” with example. 

PathParam in RESTAssured...!!! Click To Tweet

Here, 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 (pathParam) 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: ?

 

PathParam in RESTAssured...!!! Click To Tweet

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

Other Useful References:

Author

  • Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester. He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.

close

Enjoy this blog? Please spread the word :)

Follow by Email
Twitter