eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

1. Overview

In Postman, variables let us save the values and use them as required in different APIs. We can reference these values by passing them to collections, environments, or any requests. It basically makes it easier to access stored values using these variables more efficiently. We can also collaborate with multiple teammates or set up dynamic workflows over Postman using these variables.

In this article, we’ll understand variables in-depth, their types, and how we can embed them into our APIs.

2. What Are Variables?

Variables symbolize the data representation and let us access a value without manually entering it wherever we need it. They can be useful when we’ve to use the same value in multiple places. Some instances include base URL, token, and path variables. Further, using them also makes the requests more flexible as changing variables will automatically make changes at all places these variables are used.

We can define variables as key-value pairs in Postman. The key defines the variable name that allows us to access its value directly using this key.

In addition, one can also use environments for setting up a group of variables. These variables will have different values depending on the environment.

Let’s dive deep into the variables and understand the different variable scopes.

2.1. Variable Scopes

There are multiple scopes that let us process the development and testing of API in various environments with different values. Below are the variable scopes defined from the broadest to the narrowest area covered:

  • Global variables: These are accessible throughout the workspace and have the broadest scope in Postman. They can be used anywhere among multiple requests and collections within the workspace.
  • Collection variables: These variables are accessible only inside a certain collection. They are available across all the requests within a collection. Also, they don’t change based on the selected environment.
  • Environment variables: These variables let us scope the work as per the different environments. They change along with the change in the environment we are working on like local environment, staging or the production environment.
  • Data variables: These types of variables are external and define the data sets while running collections with the Collection Runner. We can extract this from a CSV or a JSON file. They have current values that don’t persist after a request or collection executes.
  • Local variables: These variables are also known as temporary variables that are only accessible through a request script. They have scope only till the current request or collection. Once the execution completes, they are no longer available.

2.2. Variable Types

Global and Environment variables can further be classified based on their types. Here’s how we can configure them:

  • Default type: Variables are of these types by default. These are shown as plain text with no additional properties.
  • Secret type: These variables hide the initial and current values for all the workspaces, similar to a password. They let us prevent any unintentional disclosure of sensitive data.

3. Defining Variables With Scopes

We can define variables in multiple types and with scopes as we discussed above. Variables can be defined at any scope in the request builder.

Firstly, we select the text and click on Set as a variable. Once done, we have to store it as a new variable. Then, we enter a key for the value and select from the different scopes available in Postman:

Screenshot-2022-08-03-at-11.37.26-PM

3.1. Setting the Response Body as Variables

The values from the request’s response body could also be set up into variables and used further in the collection. This helps in running multiple requests in sequence and creating a specific flow.

Firstly, let’s select the text we want to save and press right-click or the Control-click button to store it as a variable.

Once done, we have to choose among the relevant scope from the possible options, i.e., environment, local or global, and name the variable to save it:

Screenshot-2022-08-03-at-11.41.33-PM

3.2. Defining Global Variables

Let’s look at the steps for setting up global variables in Postman:

  1. We start by clicking on Add a new variable in the global variable section, and then entering the variable name to store it as a global variable directly.
  2. Another option is to select the value and store the variable by choosing the Global option as Type.
  3. Once done, we shouldn’t forget to mark Save icon Save and confirm the changes.

We can also download the global variables and share them with others by going through these steps:

  1. First, let’s go to Postman and select the environment type as Global in the sidebar.
  2. Then, we can click on the Export button that will export the variables to a file.
  3. We can store the file once ready by clicking Save icon Save on the system, and sharing it as required.

3.3. Defining Environment Variables

We can go through the following steps to save environment variables in Postman:

  1. Firstly, we click on the Add a new variable, and Enter the variable name.
  2. Before saving the variable, we can select the variable type as the environment.
  3. The variable will need initial and current values to be specified.
  4. Once done, we have to click on Save icon Save to confirm the changes.

3.4. Defining Collection Variables

Postman also provides the opportunity to add collection variables and use them as required.

We have to click and select Collections in the sidebar. Once done, let’s select the Variables tab to store the collection variables:

Screenshot-2022-08-07-at-12.35.30-AM

3.5. Defining Variables in Scripts

Similar to defining variables in a collection, an environment, or globally, we can also set variables programmatically in our request scripts.

All of these methods take in (variable_key, variable_value) as input:

  1. pm.globals: This method is used for defining the global variables in a request script, e.g., pm.globals.set(“variable_key”, “variable_value”);
  2. pm.collectionVariables: We can define a variable with scope as ‘collection’ with this method, e.g., pm.collectionVariables.set(“variable_key”, “variable_value”);
  3. pm.environment: This can be used for defining an environment variable with scope as current environment, e.g., pm.environment.set(“variable_key”, “variable_value”);
  4. pm.variables: This defines the local variable with local/temporary scope, e.g., pm.variables.set(“variable_key”, “variable_value”);
  5. unset: This method can be used for removing a set variable. The unset can be defined with the above variable instances as per their scope, e.g., pm.environment.unset(“variable_key”, “variable_value”);

3.6. Using Variables in Scripts

We’ve stored the variables in scripts by using the above methods. Therefore, we can retrieve their current value using these methods:

  1. pm.variables.get(“variable_key”): This will access a variable at any scope including the local.
  2. pm.globals.get(“variable_key”): This can access a global variable
  3. pm.collectionVariables.get(“variable_key”): This can access a collection variable.
  4. pm.environment.get(“variable_key”): This can access an environment variable.

Here, we can retrieve the values using variable_key. The object represents the scope level and the get() method retrieves the value.

The pm.variables.get() method also provides the option to change variable scopes without actually affecting the script functionality. It returns the variable that currently has the highest precedence.

4. Using Variables

Now, we’ve defined different variable scopes and learned how to store them in Postman. Let’s see how to use these variables in our request paths and bodies.

For referencing a variable throughout Postman, we should use double curly braces around the variable’s name. It automatically fetches the value from different variables as defined. This is standard across all of Postman and doesn’t depend on variable types and scopes:

{{studentName}}

Additionally, running CURL or hitting the request resolves the variable and updates the variable with the current value. The below request URL references the variable:

http://localhost:8080/get?student_name={{studentName}}

Let’s assume studentName is “John”. Postman retrieves the value from its variables and sends whatever value that’s currently stored there. Therefore, on hitting the above request over Postman it automatically converts it to the request:

http://localhost:8080/get?student_name=John

5. Conclusion

In this tutorial, we used Postman variables for basic initialization using the GUI mode.

In addition, we learned about their types and scopes. Also, we looked at the different places they can be initialized such as URIs, request body, and headers. Evidently, this lets us save time and space by not initializing the same values multiple times.

Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – LS – NPI (cat=REST)
announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

eBook Jackson – NPI EA – 3 (cat = Jackson)