Skip to content

Pre-Requests

The @pre directive lets you automatically execute one or more prerequisite requests before the main request runs. This is essential for flows like authentication.

Reference a request by its @id:

###
@id abc123
@name Login
POST {{baseUrl}}/auth/login
Content-Type: application/json
{
"email": "{{email}}",
"password": "{{password}}"
}
@capture env.token = body.access_token
###
@name Get Profile
@pre abc123
GET {{baseUrl}}/profile
Authorization: Bearer {{token}}

When you run Get Profile, Rext automatically:

  1. Executes the Login request first (ID abc123)
  2. Captures token from the login response
  3. Uses {{token}} in the Get Profile request

Chain multiple dependencies in sequential order:

@pre abc123
@pre def456
@name Full Flow
GET {{baseUrl}}/dashboard

Pre-requests execute in the order they are defined.

graph LR
A["@pre abc123"] --> B["Login Request"]
B --> C["@capture token"]
C --> D["Main Request"]
D --> E["Uses {{token}}"]
  1. Rext finds all @pre directives
  2. Executes each pre-request sequentially
  3. Any @capture directives in pre-requests set variables
  4. The main request runs with all captured variables available

When exporting to Postman, @pre directives are translated to pm.sendRequest() in the Pre-request Script:

pm.sendRequest({
url: "https://api.example.com/auth/login",
method: "POST",
header: [
{ key: "Content-Type", value: "application/json" }
],
body: {
mode: "raw",
raw: "{\"email\":\"user@test.com\"}"
}
}, function (err, res) {
pm.environment.set("token", res.json().access_token);
});

If the pre-request is not included in the export, Rext will ask if you want to include it as a separate item in the collection.

See Postman Export for more details.