Skip to main content

Using JS libraries

  1. Built-In JS Class Libraries

You can use the built-in JS library in Apidog using require.

var cryptoJs = require("crypto-js");
console.log(cryptoJs.SHA256("Message"));
  1. Non-Built-In JS Class Libraries

You can introduce numerous other libraries that are not built-in but have been made available on npm dynamically using the $$.liveRequire function. Only pure js libraries are supported, preferably libraries with the word browser written to support browser-side operation. Libraries containing language extensions such as C/C++ are not supported for loading and will run out of time or exceptions.

TIP

You need to download JS libraries from the network for non-built-in libraries. Therefore, you must be connected to the Internet. There will be a performance loss to downloading libraries on the run. Therefore, we recommend using built-in JS libraries first.

// Below is an example of using a non-built-in JS class library.

// Get a single npm library: camelcase
$$.liveRequire("camelcase", (camelCase) => {
camelCase("foo-bar"); // => 'fooBar'
});

//Get a multiple npm libraries: camelcase
$$.liveRequire(["camelcase", "md5"], (camelCase, md5) => {
camelCase("foo-bar"); // => 'fooBar'
md5("message"); // => '78e731027d8fd50ed642340b7c9a63b3'
});

Built-in Library List

  • Encode and Decode
    • atob(v2.1.2): Base64 decode.
    • btoa(v1.2.1): Base64 encode.
    • crypto-js(v3.1.9-1): An Encoding / decoding library, including the common encoding and decoding methods (Base64, MD5, SHA, HMAC, AES, etc.).
      • You can only require the entire module, not a submodule of the class library. View the documentation here for more details.
    • jsrsasign(10.3.0): RSA encryption / decryption. Only Apidog version >= 1.4.5 is supported.
  • Assertion
    • chai (v4.2.0): BDD / TDD assertion library.
  • Tools
  • JSONSchema Validators
    • tv4(v1.3.0):JSONSchema validator.
    • ajv(v6.6.2):JSONSchema validator.
  • Built-in NodeJS modules

Usage

Assign a variable to the corresponding module before using it.

// SHA256
var cryptoJs = require("crypto-js");
console.log(cryptoJs.SHA256("Message"));

// base64
var atob = require("atob");
console.log(atob("Message"));
TIP

You can only require the entire module when using a built-in library; you cannot require a library submodule.

// A correct example.
var cryptoJs = require("crypto-js");
console.log(cryptoJs.SHA256("Message"));

// A wrong example.
var SHA256 = require("crypto-js/sha256");
console.log(SHA256("Message"));