Skip to main content
Request chaining in Bruno allows you to execute multiple requests in sequence, pass data between them, and control the flow of your API testing workflow. This powerful feature enables you to build complex test scenarios where the output of one request becomes the input for the next.

Overview

Bruno provides several methods for request chaining:
  • bru.runRequest() - Execute requests within your collection
  • bru.sendRequest() - Send programmatic HTTP requests
  • bru.runner.setNextRequest() - Control request execution order in collection runs

bru.runRequest()

Execute any request in your collection and retrieve the response directly within your script.
Avoid using bru.runRequest() in collection-level scripts. Since collection scripts run for all requests, calling bru.runRequest() from a collection script will trigger the target request, which will also execute the collection script again, creating an infinite loop.

Syntax

showLineNumbers

Parameters

  • requestPath: The path to the request relative to the collection root, using folder names as segments and the request name (without the .bru extension) as the last segment. For a request that lives directly at the collection root, pass just the request name — for example bru.runRequest("Login"). For a request nested inside folders, join the folder names with / — for example bru.runRequest("auth/Login"). The path is resolved from the collection root, not relative to the calling request.

Returns

Returns a response object with the following fields:
  • status: HTTP status code (number)
  • statusText: HTTP status text (string)
  • headers: Response headers object
  • data: Parsed response body — automatically decoded to a JavaScript object when the response is JSON, otherwise a string
  • duration: Response time in milliseconds
  • size: Response size in bytes
  • url: The final request URL
The parsed body lives on response.data, not response.body. This differs from the res object available in post-response and test scripts, where the body is exposed as res.body / res.getBody().

Examples

Basic Request Execution

showLineNumbers

bru.sendRequest()

Send a programmatic HTTP request within your script. This allows you to make additional API calls during script execution.

Syntax

showLineNumbers

Parameters

  • method: HTTP method (GET, POST, PUT, DELETE, etc.)
  • url: The URL to send the request to
  • headers: (Optional) Request headers object
  • data: (Optional) Request data. Can be a string or object
  • timeout: (Optional) Request timeout in milliseconds
  • callback: Function to handle the response with signature (err, res)

Examples

Basic HTTP Request

showLineNumbers

POST Request with Data

showLineNumbers

bru.runner.setNextRequest()

Control the order in which requests are executed during collection runs. This allows you to skip requests or change the execution flow based on conditions.
bru.runner.setNextRequest() works only in post-request scripts or test scripts.

Syntax

showLineNumbers

Parameters

  • requestName: The name of the next request to execute (string) or null to stop execution

How it works

  • setNextRequest works with single requests - it executes the current request first, then jumps to the specified request
  • It skips all requests between the current one and the target request
  • The target request must exist in the collection and be specified by its exact name
  • For requests inside folders: Use just the request name (e.g., “request-name”), not the full path

Examples

Conditional Request Execution

showLineNumbers
  • Use bru.runRequest() for requests within your collection (faster, uses existing configuration)
  • Use bru.sendRequest() for external APIs or when you need custom request configuration
  • Avoid nested loops that could cause infinite request chains