Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

External library in Postman

I want to use linq.js for my assertions. Is there a way to include an external library in Postman?

like image 977
UserControl Avatar asked Jul 01 '15 09:07

UserControl


People also ask

What is an external library?

An external library is something that comes from an outside source. (Hence, neither you nor the language-vendor "owns" it.) Your project references it, and depends on (a certain version of) it such that "it cannot live without it," but it is not "(just) a part of this project."

What library does Postman use?

The Postman Runtime library supports request sending and collection running in Postman as well as in other interfaces including Newman, Postman's command-line collection runner.


2 Answers

No, linq.js, or any library not available in the Postman Sandbox cannot be used in Postman (by default, there is a workaround).

EDIT

Actually, if you fetch a script in a request and eval it, you can use it in Postman. An example is given in this blog post - http://blog.getpostman.com/2015/09/29/writing-a-behaviour-driven-api-testing-environment-within-postman/

like image 196
elssar Avatar answered Sep 18 '22 18:09

elssar


I am doing pretty much the same than @grinderX19.

I run this once to load my global variable:

postman.setGlobalVariable("myUtils", function myUtils() {
let utils = {};

utils.function1= function function1(Arg1, Arg2){
    <code>
};

utils.function2= function function2(Arg1, Arg2){
    <code>
};

return utils;
} + '; myUtils();'
);

Then, I am calling it like this in Postman requests:

//import the global variable
let utils = eval(globals.myUtils);

//Call a function contained by this global variable
var var1 = utils.function1(arg1, arg2);

Hope this helps.

like image 33
Mario Avatar answered Sep 16 '22 18:09

Mario