Open In App

Explain the use of environment variables in Postman requests.

Last Updated : 07 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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

  • Basic HTTP concepts
  • Knowledge of REST API

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

  • Reusable and Dynamic: Environment variables makes it possible of reusing values across requests. They allow for dynamic changes without disturbing individual requests.
  • Scoped Values: We can create multiple environments in Postman (e.g., development, testing, production). Environment variables takes care that the same variable name can hold different values within different environments.
  • Security: They store sensitive information such as API keys or tokens securely. Environment variables can be hidden from shared collections, which takes care of security and confidentiality.

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”

coll

Step 2: Create environment “GFG” using Add Button

z169

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

z170

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”.

z159

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

Recording-2023-12-05-at-003543


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads