I need help writing a common function to use across a collection of requests which will help with building a framework.
I have tried using the below format
You can declare a global function by assigning this function into a collection, environment or global variable as follows:
(number)=> { return number * number }
to reuse this function elsewhere in your collection
let numberSquared = eval(pm.variables.get('global_func'))(5)
now, numberSqaure variables has a value of 25
================================
if you need to declare a function library: you can create a collection variable and assign it this piece of code:
({
print:function() {
console.log('hello Postman')
},
squared:function(number) {
return number * number
}
})
Note: the functions have been enclosed with parentheses
to reuse this library:
let lib = eval(pm.variables.get('global_func'))
lib1.print()
console.log(lib1.squared(4))
Good luck :)