Postman Tutorial Part 20 – Use Variables in Request Builder OR How To Build Parameterized Request in Postman

Hello Folks,

We have learnt already about :-

What is Variable in Postman?

Global Variables in Postman

Environment Variables in Postman

In this post, we will see how can we use variables in request body to create parameterised request.

Consider we have an API which registers a patient on any application. You need to pass required patient data like Name, Age, Gender, Address etc. These data will vary patient to patient. Everytime data needs to be changed to register a new patient. So if we construct a request body with hardcoded data in it, we need to keep editing request body for new patient which is not best practise.

Example is below:-


{
    "name" : "Mr. Clark",
    "Age" : "25",
    "address" : "London"
}

You will face below problems if you hardcode data in request:-

  1. You need to keep changing data in request body.
  2. You might misplace data.
  3. Another member will not able to edit data properly if not aware about request body.
  4. You can not use data from external sources.
  5. You can not achieve data driven testing.
  6. We must always keep logic and data separately.

All above problems can be resolved by parameterizing request body.

We know that we can create global and environment variables. We can use them in our requests.

we will parameterized below API:-

https://restful-booker.herokuapp.com/auth

Its request body:-

{ “username ” : “admin”, “password” : “password123”

}