JetClient / jet-client-support

JetClient is an advanced REST API Client plugin for JetBrains IDEs
https://plugins.jetbrains.com/plugin/21173-jetclient
110 stars 0 forks source link
api-client api-testing http-client intellij-plugin rest-client
icon

JetClient

Version Downloads JetBrains Plugins

JetClient is a simple and powerful API client plugin for JetBrains IDEs (IntelliJ IDEA, GoLand, PyCharm, PhpStorm, etc.). It combines the best features of existing API clients with additional enhancements, all within your IDE. Key features include:

JetClient plugin screenshot

Watch the JetClient plugin video to learn about the plugin features.

Contents

Project

A Project is a root collection consisting of folders and requests. It includes its own settings, environments, variables, and an init script. Projects in JetClient are independent of the IDE project, you can have multiple JetClient projects within a single IDE project.

File Sync (Git Sync)

File Sync (Git Sync) enables saving and restoring your request collections on the local file system. This allows for easy sharing of collections with your team via Git or any other version control system (VCS).

How to Use File Sync

To exclude a specific folder from syncing, disable synchronization in its properties. This change will apply to all nested folders as well.

Environments

Environments enable the use of different sets of variables for various contexts. These are organized into Environment Groups, and you can select multiple environments simultaneously, one from each group.

A Default environment group is always available, typically including environments like Local, Staging, and Production. You can also create your own environment groups, such as User, Client, Region, API Version, and others.

Environments are defined per project and can be created in the Environments tab. Variables for these environments are set in the Variables tab.

Variables

Variables in JetClient can be defined at different levels: project, folder, and runtime.

The variables editor is divided into two sections: Shared and Local.

Project variables include environment-specific variables and globals, which are accessible regardless of the selected environment. They are organized within a JSON object with the environment as a top-level property:

{
  globals: {
    baseUrl: 'https://api.example.com'
  },
  local: {
    token: 'localToken'
  },
  dev: {
    token: 'devToken'
  }
}

Folder variables can include both general variables and environment-specific variables. General variables are accessible regardless of the selected environment, while environment-specific variables are only available when the corresponding environment is selected:

{
  myFolderVar: 'myValue',
  dev: {
    myFolderVar: 'devValue'
  }
}

Variables in JetClient can be primitive types, objects, and arrays, and are usable in scripts, requests, and folders. To utilize a variable in any field, enclose it in double curly braces: {{myVar}}. You can reference entire objects or arrays, for example in the body of a request, using {{myRequestBody}}.

Variables can also reference other variables, as shown in the example below:

{
  array: [
    {
      myProperty: 123
    }
  ],
  // This variable resolves to string "123"
  myVar: '{{array[0].myProperty}}',
  // This variable resolves to number 123
  myVar2: {{array[0].myProperty}}
}

Variable Resolution Order

Variables are resolved in the following order, from highest to lowest priority:

  1. Runtime Variables
  2. Environment-specific Local Folder Variables
  3. Environment-specific Shared Folder Variables
  4. Local Folder Variables
  5. Shared Folder Variables
  6. Variables from All Parent Folders
  7. Environment Variables
  8. Globals

Scripts

Requests and folders in JetClient can have Pre-request and Test scripts written in JavaScript, while test suites contain only Test scripts. The project includes an Init Script executed once per run, which can be used to define global functions and variables. For example:

CryptoJS = require("crypto-js");

hmacSHA256 = (message) => {
    return CryptoJS.HmacSHA256(message, jc.environment.get('secret')).toString();
}

You can then use CryptoJS and hmacSHA256 in your pre-request and test scripts.

Execution Order

Scripts are executed in the following order when you send a request or run a folder with the runner:

  1. Init script of the project (executed once per run)
  2. Pre-request scripts of all parent folders (from the root to the current folder)
  3. Pre-request script of the request
  4. Test scripts of all parent folders (from the root to the current folder)
  5. Test script of the request

Steps 2-5 are repeated for each request in the run.

For test suites, scripts execute in this order:

  1. Init script of the project
  2. Test script of the test suite

Scripts from jc.runRequest, jc.runFolder, or jc.runTestSuite follow the same execution order as for requests, folders, and test suites.

Scripting Library

JetClient built-in library is similar to Postman's but instead of pm it is called jc. For example,

jc.test("Status code is 200", () => {
    jc.expect(jc.response.code).to.eql(200)
})

JetClient scripts can utilize the Chai Assertion Library BDD. For more details, see the JetClient Library documentation. Also, see JetClient Library Types for type definitions.

External Libraries

JetClient includes built-in libraries such as ajv, atob, btoa, chai, cheerio, crypto-js, csv-parse/lib/sync, lodash, moment, tv4, uuid, and xml2js, which you can import using the require function. Additionally, you can add your own libraries to the scripts. Navigate to Settings > Tools > JetClient and set the Libraries directory. If you are using npm libraries, specify the directory containing your package.json and node_modules. Otherwise, use the directory where your script libraries are located. You can then use require to import your libraries.

Cookies

Manage cookies using the Cookies Manager. To open it, click on Cookies Manager in the toolbar of the tool window.

Proxy

Proxies are supported using the IDE Proxy Settings.

HTTP/2

To send a request using the HTTP/2 protocol, please select HTTP/2 option in Settings > Tools > JetClient > HTTP Version.

Import

JetClient supports importing collections from various sources:

To import a cURL request, simply copy the cURL command and paste it into the URL field of a request.

Contribution

Privacy