- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is Pre Requests scripts in Postman?
The Pre-Request scripts are executed before the execution of requests. These scripts are implemented in JavaScript and mainly created to execute pre-requisite conditions like declaring request headers, parameters, variables, or an output.
We can create Pre-Request Script to define the sequence of execution of requests in a Collection. A Pre-Request Script is also utilized for scenarios where value returned from a request is required in the following request or a value returned from a request should be captured prior to the next request.
These scripts are defined in the Pre-request Script tab in Postman.
Incorporate the below JavaScript in the Pre-Request Script tab −
console.log("This is a Postman Tutorial in Tutorialspoint")
Send a GET request for an endpoint.
Postman Console Output −
Here, the message - This is a Postman Tutorial in Tutorialspoint gets displayed prior to the execution of the GET request since it has been added as a part of the Pre-Request Script.
A Pre-Request Script can be added for a Collection with the below steps −
Step1 − Click on the three dots to the right of the Collection name in the sidebar. Then click on Edit.
Step2 − EDIT COLLECTION window shall open. Select the Pre-Request Scripts tab and then add a script. Finally, click on the Update button.