Global functions via Collection level folder?

The problem had perplexed me for a while until I found the common way mentioned above. However, it still leaves a warning icon for each eval line, which indicates “eval can be harmful” in the postman interface.
Recently, I’ve found another way and post it here:
Users can create a prototype object with the proper function you want in the pre-request script section, like this:

Object.prototype.sayHello = function(name){
    console.log(`Hello! ${name}`);
};

and call that function everywhere after that. It just required a defined object, like this:

let obj = {};
obj.sayHello('Griffin');

Or you don’t even need the declaration of the object but use some built-in objects instead, like lodash (you pretend it has the function :smile: )

_.sayHello('Griffin');

It’s working on my side.

9 Likes