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.

Bruno Screenshot

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.

Exploring Bruno API Testing: What is Bruno and How to Download and Install Bruno
Bruno is a Git-friendly and offline-first open-source API client aimed at revolutionizing API development tools like Postman and Insomnia.

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:

  1. Go to the Collection Settings.
  2. Click on the Variables tab.
  3. Add your variable name and value in the Pre Request Vars section.
  4. Save your changes.
Creating a Collection Variable

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:

  1. Open Folder Settings from the dropdown menu in the sidebar.
  2. Go to the Vars Tab.
  3. Add your variable name and value.
  4. Save your changes.
Creating a Folder Variable

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:

  1. Open your Request.
  2. Go to the Vars Tab.
  3. Input your variable name and value.
  4. Save your changes.
Creating a Request Variable

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:

  1. Runtime Variables
  2. Request Variables
  3. Folder Variables
  4. Collection Variables
  5. 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.

An Alternative to Consider: EchoAPI.png

In summary, whether you're using Bruno or exploring options like EchoAPI, understanding how to leverage variables can significantly enhance your API testing process.