Scripts

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

Common tasks

Migration

See Also

  • Scripting API: The objects and functions available to request scripts.