insomnia-plugin-batch-requests
v1.3.0
Published
An Insomnia plugin that can send a request multiple times, varying the request with data taken from a CSV file and extracting information from the responses back into the CSV file
Downloads
49
Readme
insomnia-plugin-batch-requests
The Batch Requests plugin for Insomnia adds the ability to send a request repeatedly, changing parts of every request by variable data, taken from a CSV file. For every response, some data can be collected and added to the CSV file.
- Repeatedly send a request by reading data from a CSV file
- Extract data from JSON responses and write it back to the CSV file
- Works well if not using the plugin (when sending the request manually)
- Add a delay between each request
- Run multiple requests in parallel
- Supports non-JSON responses too (but can't extract response data in such cases)
For a short demonstration, watch this:
Installing
Go to the Application>Preferences
menu in Insomnia, then go to the Plugins
tab, search for insomnia-plugin-batch-requests
and install it.
Usage
The plugin adds a template tag to mark the places that you want to replace. To add it, press Ctrl+Space
, search for the Batch
tag and press Enter
. Then, double click the tag to configure it. The tag can be inserted anywhere in the request (e.g. in the URL, query parameters, headers, or body)
When configuring the tag, set the following two values:
- The name of the CSV column that will be replaced in this tag's location. Copy it from the first line of the CSV file, exactly (including capitalization)
- A sample value. This value will be used when sending the request manually. This is the value that you would have to edit manually if this plugin did not exist.
The live preview will always show the value of the Sample value
field, and this same value will be replaced when sending the request manually (e.g. via Insomnia's main Send button) The value will only vary when sending the request via the Batch Request dropdown option (see below).
The plugin also adds a context menu option to all requests. To see it, click on the dropdown arrow to the right of a request on the sidebar, then select the Batch Requests
option. This will open the plugin dialog.
On the plugin dialog, you should:
- Select a CSV file using the button. The file should have one column for each different placeholder/template tag that you have selected, plus one column for each result that you want to extract from the responses. The response/output columns can be empty, since they will be filled by the plugin.
- Review the loaded data in the table. It will show the first five rows of the CSV file. It is provided as a sanity check, so that you can verify that the CSV is being parsed correctly.
- (Optional) Configure the data that you want to output by adding
Outputs
. For each one, use the dropdown on the left to specify a CSV column, and write a JSONPath expression in the text field on the right. In the image below, the$.total
field will be written to thesales
column in the CSV file. This plugin uses thejsonpath-plus
syntax, which is also used by Insomnia - Click the
Run!
button at the bottom of the dialog. It will only become active when you have chosen a file and (if any outputs exist) completely filled all Outputs. - Click the
Save
button to write the extracted data back to the CSV file, if you need it. Wait until all requests have been performed (as indicated by the progress bar) before clicking this button.
Extra settings
There are two additional options that can be set when sending batch requests. They appear in the Run Config section, above the progress bar:
- Delay in seconds (available since
v1.1.0
): Inserts a delay before sending each request. It's useful if the remote API enforces a rate limit or it's otherwise desired to throttle requests. By default it's set to 0. Can also be altered for the entire Request Collection (see below) - Parallel requests (available since
v1.3.0
): Controls the number of requests that can be in flight at the same time. If set to a value greater than 1, it'll send multiple requests in parallel. Once a request is done, another one will start. By default it's set to 1
Global configuration
Since v1.2.0
, there is a Global Configuration dialog in which you can select a default request delay, in case you usually work with servers that require a delay between requests.
- Click on the dropdown to the right of the workspace name.
- Click the
Batch Requests: Settings
option. - A dialog will open, containing a number field called
Default delay
. Set its value to your preferred delay. - Click the Save button. It will only be enabled after you make a change to the field.
- Dismiss the Global Configuration dialog.
- From now on, whenever you open the main plugin dialog by right-clicking a request, the Delay field will be prefilled with your preferred delay. You can always adjust it.
Development
- Identify your Insomnia plugin folder. On Ubuntu, it should be
~/.config/Insomnia/plugins
. Alternatively, open Insomnia, select theApplication>Preferences
menu, go to the Plugins tab, then click theReveal Plugins Folder
button. - On that folder, run
git clone https://github.com/jreyesr/insomnia-plugin-batch-requests
. - Run
npm i
. - Run
npm run dev
. This will start a dev server that will generate thedist/main.js
file and keep it updated whenever you change the source files. - Open the Insomnia Plugins dialog (see the first step). It should display the plugin, since it's in the correct folder. It's not necessary to manually install it.
- Create and checkout a new branch.
- Hackity hack on the source files.
- Whenever you save a file, the
dist/main.js
file will be updated. To make Insomnia pick up the changes, select theTools>Reload plugins
option from the top menus. Alternatively, pressAlt+T
, then release both, then pressR
. - To run tests, run
npm run test
- Make commit.
- GOTO 6
- Update the package version in
package.json
. - When done, submit a PR and merge it. If releasing a new version, see the next section.
Releasing
- Ensure that the package version in
package.json
has been bumped. - Make all required commits, ensure that
master
has the code. - Create a Github Release, tag it like the version in
package.json
. - The CD runner should create the release and publish it.