Introduction
Welcome back! In the previous lesson, you built out your Postman collection with all the necessary CRUD requests. You've already been using the {{baseUrl}} variable, which is excellent. This lesson formalizes that practice by focusing specifically on Postman Environments.
The goal is to master the use of environment variables so you can avoid hardcoding URLs in your requests. This is a critical skill for the exam for two main reasons:
- Flexibility: It allows you to switch between your local development server (
http://localhost:5000) and your live deployed server with a single click, without having to edit every request. - Professionalism: It's a standard industry practice that keeps your test collections clean, maintainable, and portable.
By the end of this lesson, you will be able to confidently define and use Postman environment variables, ensuring your setup is robust and exam-ready.
The 'Why' Behind Environments
A Postman Environment is simply a set of key-value pairs (variables). You can create different environments for different contexts, such as local development, staging, or production.
For our purposes, the most important variable is baseUrl. Hardcoding http://localhost:5000 into every request is inefficient and error-prone. By using {{baseUrl}}, we define the base URL in one place. If the port changes or when you deploy your API to a live URL, you only need to update it in that single location.
Let's see this in action.
Postman Environments: How to Set Up and Use Them
The Postman team has a concise video that perfectly demonstrates how to create and use environments. This will give you a quick visual overview.
Watch the segment from 01:03 to 02:25. Focus on how a new environment is created, how a variable like base_url is defined, and how it's used in a request.
Practical Exercise: Configure Your Environment
Now, let's apply this to your project. You should already have a Local Development environment, but we'll walk through the process deliberately to solidify the pattern.
Step 1: Navigate to Environments
In Postman, click on the Environments tab on the left sidebar. If you have an existing Local Development environment, click on it. If not, click the + button to create a new one and name it Local Development.
Your screen should look similar to this, showing a table where you can define your variables.

Step 2: Define the baseUrl Variable
In the table, create a new variable:
- VARIABLE:
baseUrl - INITIAL VALUE: Enter your local server address, for example,
http://localhost:5000. (Use the port number your server is running on). - CURRENT VALUE: After typing in the
INITIAL VALUE, theCURRENT VALUEfield will auto-populate. For now, they can be the same.
A quick note on Initial vs. Current values: Initial Value is what gets shared when you export the environment for team collaboration. Current Value is what Postman uses locally and is not shared, making it ideal for secret keys or tokens. For baseUrl, it's fine for them to be identical.
Remember to Save your changes using the button in the top right.
Step 3: Use the Variable in Your Requests
- Go back to your collection and open any request (e.g.,
GET All Products). - In the URL bar, replace the hardcoded server address with your new variable:
- Instead of:
http://localhost:5000/api/products - Use:
{{baseUrl}}/api/products
- Instead of:
- Make sure your
Local Developmentenvironment is selected in the environment dropdown at the top-right of the Postman window. - If you hover your mouse over
{{baseUrl}}, Postman will show you a tooltip with its resolved value, confirming it's working correctly.

Step 4: Final Check
Quickly go through all the requests in your collection and ensure that every single one uses {{baseUrl}} instead of a hardcoded URL. This is a fast but critical check to ensure your entire collection is portable.
For a quick written reference on this topic, you can review the "Configuring Environments" section of the following article.
How to Implement API Testing with Postman - OneUptime
The article 'How to Implement API Testing with Postman' provides a clear, text-based example of setting up a baseUrl variable.
Quickly read the sections titled 'Setting Up Your First Collection' and 'Configuring Environments'. Focus on the JSON example for a 'Development' environment and how {{baseUrl}} is used in the request URL. This reinforces what you just did.
Conclusion
You have now correctly and deliberately configured your Postman environment. This simple practice of using a {{baseUrl}} variable is a major step towards a professional and efficient testing workflow. It makes your collection clean, easy to manage, and ready for deployment.
Key Takeaways:
- Environments store variables that can change between different setups (local, production).
- The
{{variableName}}syntax is used to reference variables in your requests. - Always use
{{baseUrl}}to avoid hardcoding URLs. - Ensure the correct environment is active using the dropdown menu in the top-right corner of Postman.
Next Up:
With your collection and environment fully configured, there's just one last step in the Postman workflow: exporting your work. In the next lesson, you'll learn how to export your Postman collection and environment as JSON files, which is exactly what you'll need to do for your final exam submission.