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.
Basic Syntax
Section titled “Basic Syntax”Reference a request by its @id:
###@id abc123@name LoginPOST {{baseUrl}}/auth/loginContent-Type: application/json
{ "email": "{{email}}", "password": "{{password}}"}
@capture env.token = body.access_token
###@name Get Profile@pre abc123GET {{baseUrl}}/profileAuthorization: Bearer {{token}}When you run Get Profile, Rext automatically:
- Executes the Login request first (ID
abc123) - Captures
tokenfrom the login response - Uses
{{token}}in the Get Profile request
Multiple Pre-Requests
Section titled “Multiple Pre-Requests”Chain multiple dependencies in sequential order:
@pre abc123@pre def456@name Full FlowGET {{baseUrl}}/dashboardPre-requests execute in the order they are defined.
Cycle Protection
Section titled “Cycle Protection”How It Works
Section titled “How It Works”graph LR A["@pre abc123"] --> B["Login Request"] B --> C["@capture token"] C --> D["Main Request"] D --> E["Uses {{token}}"]- Rext finds all
@predirectives - Executes each pre-request sequentially
- Any
@capturedirectives in pre-requests set variables - The main request runs with all captured variables available
Postman Export
Section titled “Postman Export”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.
Next Steps
Section titled “Next Steps”- Learn about assertions for response validation
- Explore retry and timeout settings