Pre-request scripting in Postman
I just discovered this feature in the awesome Postman tool — the pre-request scripting tab.
You can use it to generate variables for use in your requests. This was super useful for us just recently when we started testing endpoints with date fields requiring To and From dates.
Open up Postman and go to a request, then open the Pre-Request Script tab. Here you can write javascript, with several well-known libs included (moment and lodash to name a few):
In the case above, we use moment to generate a date for today and one for 24 hours into the future, like so:
In order to use these values in the request, we sprinkle in some Postman magic like this:
Postman even does some limited syntax checking for you (hence the `;` ’s everywhere, no one uses them in JS, right!?)
Mode details on the pre-request scripting feature.
Go grab Postman now if you haven’t already and send the Postman team some love!