Overview

This page documents the Pre-request & Test Scripts feature of Request Man.

Scripts - Pre-request & Tests Pre-request Tests 📝 Pre-request Script Write JavaScript code to execute before sending the request. Use the rm object to access environment variables and set dynamic values. 1 2 3 4 5 6 7 8 9 10 11 12 13 // Set timestamp variable const timestamp = Date . now (); rm .environment. set ( "timestamp" , timestamp); // Generate random ID const randomId = Math . floor ( Math . random () * 10000 ); rm .environment. set ( "userId" , randomId); // Add custom header rm .request.headers. add ({ key: "X-Custom-Header" , value: "API-Request" }); console . log ( "Pre-request executed!" );
Documentation in Progress: Full documentation for this feature coming soon!

Key Features

The Pre-request & Test Scripts feature provides powerful capabilities for API testing and development.

Tests Tab - Response Validation Pre-request Tests ✅ Tests (Post-response) Write tests to validate the response. Use rm.test() to create assertions and verify your API responses match expected values. 1 2 3 4 5 6 7 8 9 // Validate status code rm . test ( "Status is 200" , function () { rm .response.to.have. status ( 200 ); }); // Validate JSON response rm . test ( "Response has data" , function () { const data = rm .response.json(); rm . expect (data.users). toBeArray (); }); ✓ Test Results (2/2 passed) Status is 200 Response has data Execution Time: 145ms Tests Passed: 2 / 2 Tests Failed: 0

Getting Started

Access the Feature

Navigate to Pre-request & Test Scripts in the Request Man interface.

Configure Settings

Set up your Pre-request & Test Scripts preferences.

Start Using

Begin using Pre-request & Test Scripts in your API workflows!

⚡ Scripts Workflow 1 Write Pre-request Script Set variables & headers 2 Send Request Execute API call 3 Run Tests Validate response 4 View Results Check test output 💡 Pro Tip: Scripts can access environment variables, set new variables, and chain multiple requests!

Examples

Here are practical examples of using Pre-request & Test Scripts:

Example: Authentication Token Flow 📝 Pre-request Script // Get auth token from login const loginUrl = "https://api.example.com/login" const response = await fetch (loginUrl) const data = await response. json () rm .environment. set ( "token" , data.token) 🌐 API Request URL: https://api.example.com/users Header: Authorization: Bearer {{token}} ✨ Token automatically injected! ✓ Test Script // Validate response rm . test ( "Status is 200" , () => { rm .response.to.have. status ( 200 ) }) rm . test ( "Has users array" , () => { rm . expect ( rm .response.json().users). toBeArray () }) ✓ Test Results - All Passed! Status is 200 PASS Has users array PASS ✅ 2/2 tests passed Duration: 156ms

Tips & Best Practices

Tip 1

Learn the keyboard shortcuts for faster workflow.

Tip 2

Use variables for flexibility across environments.

Tip 3

Save and organize your work in collections.

Tip 4

Check the console for detailed logging information.