Skip to content

feat: User Prompt Variables Documentation #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added public/screenshots/variables/prompt-var.webp
Binary file not shown.
3 changes: 2 additions & 1 deletion src/pages/variables/_meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default {
"folder-variables": "Folder Variables",
"request-variables": "Request Variables",
"runtime-variables": "Runtime Variables",
"prompt-variables": "Prompt Variables",
"process-env": "Process Environment Variables",
"interpolation":"Variables Interpolation"
"interpolation":"Variables Interpolation"
}
21 changes: 16 additions & 5 deletions src/pages/variables/overview.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Callout } from "nextra/components";

# Variables

### Overview
Expand All @@ -6,26 +8,25 @@ Variables in the Bruno allow you to store dynamic values that can be reused acro

### Types

There are 6 types of variables you can create:
There are 7 types of variables you can create:

- [Global Environments Variables](./global-environment-variables.mdx)
- [Environment Variables](./environment-variables.mdx)
- [Collection Variables](./collection-variables.mdx)
- [Folder Variables](./folder-variables.mdx)
- [Request Variables](./request-variables.mdx)
- [Runtime Variables](./runtime-variables.mdx)
- [Prompt Variables](./prompt-variables.mdx)

Additionally, Process Environment Variables can be defined in an external environment configuration file:

- [Process Environment Variables](./process-env.mdx)

Runtime variables get the highest precedence. Process Environment Variables are accessed using the `{{process.env.VAR_NAME}}` syntax and hence don't compete with the above.

### Variable Precedence and Scope

When a variable is accessed, the following precedence is used to determine which value is used:

<div style={{ display: 'flex', justifyContent: 'center', fontFamily: 'sans-serif', marginTop: '2em', width: '100%' }}>
<div style={{ display: 'flex', justifyContent: 'center', fontFamily: 'sans-serif', marginTop: '2em', width: '100%', textAlign: 'center' }}>
<div style={{ display: 'flex', alignItems: 'flex-start', position: 'relative', width: '420px' }}>
<div style={{ position: 'absolute', left: '-120px', top: 0, height: '100%', display: 'flex', flexDirection: 'column', justifyContent: 'space-between', fontSize: '0.85em', color: '#555', textAlign: 'right', width: '120px' }}>
<div style={{ paddingRight: '10px' }}>↑ Higher Precedence</div>
Expand All @@ -42,7 +43,9 @@ When a variable is accessed, the following precedence is used to determine which
</div>
</div>

Runtime variables get the highest precedence. Process Environment Variables are accessed using the `{{process.env.VAR_NAME}}` syntax and hence don't compete with the above.
- Runtime variables get the highest precedence.
- Prompt Variables are defined using the `{{?:Prompt String}}` syntax and hence don't compete with the above.
- Process Environment Variables are accessed using the `{{process.env.VAR_NAME}}` syntax and hence don't compete with the above.

### Variable Storage

Expand Down Expand Up @@ -81,6 +84,10 @@ Each variable has its own storage location either within your collection file or
<td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>Global</td>
<td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>Local storage</td>
</tr>
<tr style={{ backgroundColor: 'rgba(128, 128, 128, 0.1)' }}>
<td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>Prompt</td>
<td style={{ padding: '8px', border: '1px solid #ddd', width: '50%', fontStyle: 'italic' }}>Never stored</td>
</tr>
<tr style={{ backgroundColor: 'rgba(128, 128, 128, 0.1)' }}>
<td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>Process Environment</td>
<td style={{ padding: '8px', border: '1px solid #ddd', width: '50%', fontStyle: 'italic' }}>Separate `.env` file</td>
Expand Down Expand Up @@ -112,3 +119,7 @@ console.log(bru.getVar('myVar')) // Runtime variables
### Scripting API

Please see the [Scripting API](/scripting/javascript-reference#collection-variables) for more information on how to access variables in your scripts.

<Callout type="info">
Prompt variables are not accessible via the Scripting API.
</Callout>
87 changes: 87 additions & 0 deletions src/pages/variables/prompt-variables.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Callout } from "nextra/components";

# Prompt Variables

## Overview

Prompt variables are a special type of **ephemeral variable** in Bruno that allow you to prompt the user for a value at the time a request is executed. Unlike other variable types, prompt variables do not have a predefined value and are not persisted anywhere, they exist only for the duration of a single request execution. Prompt variables are useful for sensitive data, ad-hoc values, or any scenario where you want the user to provide input before sending a request.

Prompt variables are scoped within a request, meaning they are available only to the request in which they are defined during execution, and their values are not persisted after the request completes.

### Syntax

Prompt variables use the following syntax:

```handlebars
{{?:Prompt Here}}
```

- The `?:` indicates that this is a prompt variable.
- The text after the colon (`:`) is the prompt message shown to the user.

Prompt variables are highlighted in <span style={{ color: "dodgerblue" }}>blue</span> in the Bruno UI.

![prompt-var](/screenshots/variables/prompt-var.webp)

### Prompt Variable Modal

When prompt variables are detected, Bruno displays a modal dialog listing all prompt variables and their prompt messages. You may provide values for each before the request is sent. If you cancel the modal, the request will not be sent.

### Using Prompt Variables

You can use prompt variables anywhere markup variables are supported in Bruno, such as in URLs, headers, query parameters, and request bodies.

When you execute a request containing one or more prompt variables, Bruno will display a modal dialog prompting you to enter a value for each unique prompt variable. If the same prompt variable appears multiple times in a request, you will only be prompted for it's value once, and all instances will be replaced with the value you provide.

![prompt-var-modal](/screenshots/variables/prompt-var-modal.webp)

<Callout type="info">
If you leave a prompt variable blank, it will be replaced with an empty string in the request.
</Callout>

### Deduplication

If you use the same prompt variable multiple times in a request, Bruno will only prompt once and substitute the value everywhere.

#### Example:

For the following request referencing the `Username` prompt variable twice:

```json
{
"user": "{{?:Username}}",
"profile": {
"name": "{{?:Username}}"
}
}
```

You will only be prompted for "Username" once:

![prompt-var-dedupe](/screenshots/variables/prompt-var-dedupe.webp)

### Behavior in Bruno CLI

If you run a collection containing prompt variables using Bruno CLI, any requests containing prompt variables will be **skipped** and marked as `skipped` in the CLI output. This is because CLI does not support interactive prompting.

### Behavior in Runners

If you run a collection containing prompt variables using the Bruno Runner, any requests containing prompt variables will be **skipped** and marked as `skipped` in the run results. This is because the Runner does not support interactive prompting.

![prompt-var-runner](/screenshots/variables/prompt-var-runner.webp)

### Viewing Prompt Variables

Prompt variables are ephemeral and only exist during request execution. They are not shown in any variables viewer and are not persisted.

<Callout type="warning">
Prompt variables are only available during the execution of a request and are not persisted or accessible after the request completes.
</Callout>

## Notes

- Prompt variables are ideal for sensitive or temporary values you do not want to save or share.
- If you do not provide a value, the prompt variable will be replaced with an empty string.
- Prompt variables are highlighted in blue in the Bruno UI.
- Prompt variables are not available in scripts (pre-request or post-response).
- Bruno CLI and Bruno Runner both skip requests containing prompt variables.