Created
April 13, 2018 16:45
-
-
Save aggieben/a765d4828df00c8561b2b36e1a4f65b1 to your computer and use it in GitHub Desktop.
Postman Pre-Request Script Variable Substitution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function replaceVariables(templateString) { | |
let tokens = _.uniq(templateString.match(/{{\w*}}/g)) | |
_.forEach(tokens, t => { | |
let variable = t.replace(/[{}]/g, '') | |
let value = environment[variable] || globals[variable] | |
templateString = templateString.replace(new RegExp(t,'g'), value) | |
}); | |
return templateString | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment