Exploring Bruno API Testing: A Deep Dive into Bruno Variables
Bruno is an innovative API testing tool designed to streamline the process of API development and testing.A standout aspect of Bruno is its use of variables, which allows for dynamic data handling across requests and environments.
Bruno is an innovative API testing tool designed to streamline the process of API development and testing. With its user-friendly interface and powerful features, it enables developers to execute and manage APIs efficiently. A standout aspect of Bruno is its use of variables, which allows for dynamic data handling across requests and environments. This article will explore the different types of variables you can use in Bruno and how they enhance your API testing experience.
What Are Variables in Bruno?
Variables in Bruno let you store dynamic values that can be reused throughout your API requests. By using variables, you can manage frequently changing data like tokens or API endpoints in one central place. This not only improves efficiency but also enhances the maintainability of your API tests.
Types of Variables
Bruno supports five main types of variables:
Collection Variables
Collection variables are scoped to a specific collection. They are great for storing values used across multiple requests.
How to Create a Collection Variable:
- Go to the Collection Settings.
- Click on the Variables tab.
- Add your variable name and value in the Pre Request Vars section.
- Save your changes.
Usage:
You can reference a collection variable using the {{varName}}
syntax.
Folder Variables
Folder variables are specific to a folder within a collection, making them useful when you have multiple requests that share the same value.
Creating a Folder Variable:
- Open Folder Settings from the dropdown menu in the sidebar.
- Go to the Vars Tab.
- Add your variable name and value.
- Save your changes.
Usage:
Like collection variables, folder variables are accessed using the {{varName}}
syntax.
Request Variables
Request variables are tied to specific requests of the API. Note that since version 1.28.0, all request variables are treated as strings.
Creating a Request Variable:
- Open your Request.
- Go to the Vars Tab.
- Input your variable name and value.
- Save your changes.
Runtime Variables
These are temporary variables available only during the API client runtime. They are useful for managing session tokens or dynamically generated data.
Creating a Runtime Variable:
Use the bru.setVar(name, value)
function.
Example:
bru.setVar("token", "res.body.token");
Process Environment Variables
These variables allow for flexibility within your API tests and can be accessed directly with the {{process.env.VAR_NAME}}
syntax.
Variable Precedence
When accessing variables, Bruno follows a hierarchy:
- Runtime Variables
- Request Variables
- Folder Variables
- Collection Variables
- Environment Variables
This means runtime variables take precedence over others.
Conclusion: Why Choose EchoAPI?
For those looking for an alternative, I highly recommend EchoAPI for VS Code. It's a lightweight collaboration tool that supports features like API design, debugging, and automated testing—all without requiring a login. With EchoAPI , you can enjoy a user-friendly experience with better integration into your development workflow.
In summary, whether you're using Bruno or exploring options like EchoAPI, understanding how to leverage variables can significantly enhance your API testing process.