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