Scripts
Run JavaScript before and after requests to prepare data and test responses.
Overview
Scripts let you add logic to a request. A pre-request script runs before Relay sends the request and can set variables, change headers or fetch data from another endpoint. A post-response script runs after the response arrives and can check it with tests, extract values for later requests, and log what it finds.
Requests, folders and collections can each have scripts, and they run from the outside in: the collection's first, then each folder's, then the request's. Relay's scripting API matches Postman's, so most Postman scripts run unchanged, and it includes popular libraries such as chai, lodash and crypto-js.
Scripts that arrive from outside Relay, such as through an import or a Git pull, don't run until you allow them.
Topics
Essentials
- Running scripts before and after requests: Add pre-request and post-response scripts to requests, folders and collections.
- Allowing scripts to run: Review and allow scripts that changed outside Relay before they run.
Common tasks
- Testing responses: Check responses automatically with tests and assertions.
- Reading and writing variables in scripts: Read variables and set new values from pre-request and post-response scripts.
- Sending requests from scripts: Send other requests from a script and use their responses.
Migration
- Migrating scripts from Postman and Bruno: Run your existing Postman and Bruno scripts in Relay and learn what's different.
See Also
- Scripting API: The objects and functions available to request scripts.