Open In App

Explain the use of environment variables in Postman requests.

Postman is a powerful API development tool which offers a feature known as environment variables. These variables are used for efficiently testing and development of APIs by allowing users to manage dynamic values across requests easily.

Prerequisites

What are Environment Variables in Postman?

Environment variables in Postman acts as placeholders for values that can change or need to be reused across multiple requests. These variables give the option to hold and repeat parameters in the requests, collections, scripts and so on. If we need to modify a value, we need to do it in only one place.

Advantages of Using Environment Variables

How to Use Environment Variables in Postman Requests

Step 1: After downloading and installing the Postman, open the software. Add a new Collection using `+` icon and give it a name like “Test”



Step 2: Create environment “GFG” using Add Button

Step 3: Add a environment variable; ‘var‘ and add a initial value 1 and click on save.

Step 4: When you hover, on the name of your collection, 3 dots will appear. Click on those 3 dots, and then click on “Add new request”.

Step 5: Now You can simply paste the API in the space provided and select the environment “GFG” and select the API type you are requesting from the dropdown like GET,POST, PUT, DELETE etc. Output will be shown in the body with the status code.

API Used:

https://jsonplaceholder.typicode.com/posts/?userId={{var}}

Output

Article Tags :