Giter Club home page Giter Club logo

insomnia-plugin-batch-requests's Introduction

insomnia-plugin-batch-requests

npm Coverage Status

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 (or other sources, such as the response headers, status code and time taken) 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. Can still use response headers and status code)

A diagram displaying the flow of data in the plugin

For a short demonstration, watch this:

A GIF animation displaying the usage of the plugin

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)

A screenshot showing a template tag that marks a replacement location. It specifies the CSV column that will be used and a sample value that will be sent when manually sending the request

A screenshot showing the configuration UI for the template tag. It contains form fields to configure the column name that will be accessed from the CSV file, and a sample value that will be sent when manually sending the request

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.

A screenshot showing the context menu aded by the plugin. A request has been right-clicked, and the context menu contains a new "Batch Requests" option under the Plugins section

A screenshot showing the main plugin UI. From top to bottom, there is a button to load a file, a table showing a preview of the data, a series of fields to specify output data, and a button to run the request multiple times

On the plugin dialog, you should:

  1. 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.
  2. 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.
  3. (Optional) Configure the data that you want to output by adding Outputs:
    • Use the dropdowns on the left to specify a CSV column
    • Use the dropdowns on the middle to specify from where the data will be collected. See below for the available sources
    • If data is being read from the response body, write a JSONPath expression in the text fields on the right. In the image below, the $.total field will be written to the sales column in the CSV file. This plugin uses the jsonpath-plus syntax, which is also used by Insomnia
    • If data is being read from the response headers, write a header name in the text fields on the right. For example, write content-length to fetch the response's length. This field is case-insensitive (i.e. you don't need to match the exact casing returned by the server)
  4. If desired, specify a delay between requests, or a number of parallel requests. By default, no delay is applied, and requests are sent in sequence (one after the other, with no parallelization). See below for more information.
  5. 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.
  6. 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.

Sources of output data

a closeup of the UI, showing the Outputs section, with one output of each type (response body, response header, response status code, and request elapsed time)

Since v1.4.0, it's possible to extract data from several places in the response:

  • The response body (must be JSON). This is the default option and the only one available before v1.4.0. This option requires specifying a JSONPath expression to extract a specific value from the JSON response, such as $.data.id
  • The response headers. This option requires specifying a header name,
  • The response status code (the numerical one, such as 200). This option does not require any further configuration
  • The time taken by the request (in milliseconds). This option does not require any further configuration

The source of data is chosen in the center dropdown of each Output. If required, the right-hand text field will appear and must contain something, otherwise it'll be hidden.

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:

A screenshot with the extra settings marked. The settings are two numerical inputs titled "Delay in seconds" and "Parallel requests" respectively

  • 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.

  1. Click on the dropdown to the right of the workspace name.
  2. Click the Batch Requests: Settings option.
  3. A dialog will open, containing a number field called Default delay. Set its value to your preferred delay.
  4. Click the Save button. It will only be enabled after you make a change to the field.
  5. Dismiss the Global Configuration dialog.
  6. 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.

a screenshot showing the workspace menu, with a new option for the plugin's configuration

a screenshot showing the configuration dialog, with a field for the default delay and a Save button

Development

  1. Identify your Insomnia plugin folder. On Ubuntu, it should be ~/.config/Insomnia/plugins. Alternatively, open Insomnia, select the Application>Preferences menu, go to the Plugins tab, then click the Reveal Plugins Folder button.
  2. On that folder, run git clone https://github.com/jreyesr/insomnia-plugin-batch-requests.
  3. Run npm i.
  4. Run npm run dev. This will start a dev server that will generate the dist/main.js file and keep it updated whenever you change the source files.
  5. 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.
  6. Create and checkout a new branch.
  7. Hackity hack on the source files.
  8. Whenever you save a file, the dist/main.js file will be updated. To make Insomnia pick up the changes, select the Tools>Reload plugins option from the top menus. Alternatively, press Alt+T, then release both, then press R.
  9. To run tests, run npm run test
  10. Make commit.
  11. GOTO 6
  12. Update the package version in package.json.
  13. When done, submit a PR and merge it. If releasing a new version, see the next section.

Releasing

  1. Ensure that the package version in package.json has been bumped.
  2. Make all required commits, ensure that master has the code.
  3. Create a Github Release, tag it like the version in package.json.
  4. The CD runner should create the release and publish it.

insomnia-plugin-batch-requests's People

Contributors

jreyesr avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

insomnia-plugin-batch-requests's Issues

Extract HTTP status response code

This plugin is amazing. I use it almost every single week and it's helping me to save time when I have to send tons of requests to the same endpoint with different parameters.

From the very beginning I started using it I missed a feature: it would be nice to extract the HTTP status response, so we could have a CSV after the execution as follows:

Parameter1,Parameter2,StatusResponse
hello,bye,200
hola,adios,200
ciao,ciao,200
failtest,failtest,500

Thanks for your work.

Regards,
Jose

Request history not visible

Steps to reproduce

  1. Create a new request in any collection
  2. Use a batch variable
  3. Create a CSV file using that variable
  4. Run Batch Requests with the CSV file
  5. Press Ctrl+Shift+H or (attempt to) click the history on the top right of the right panel (the panel that shows responses)

Expected behavior
The history menu drops down with all responses from the batch

Actual behavior
Nothing happens when using the keyboard shortcut and the history button in the responses panel isn't there to click

Additional context

  • When running the request as a normal request at least once AFTER running the request batch, the other requests DO show up
  • When running the request as a normal request at least once BEFORE running the request batch, the other requests DON'T show up

Therefore I expect that the history items do get added to the list, but the GUI doesn't get refreshed after doing so.

Possible solution
Refresh the request history part of the GUI after running a request batch.

Need iteration delay to avoid API rate limiting

This plugin is the closest thing to emulate Postman runners - great work.

When running long iterations a rate limit can be triggered, but if there was a way to set an iteration interval it would help to avoid this. Can it be done? Here's the Postman method as an example. It's in milliseconds but seconds would be enough.
iteration

Runner stops after first iteration when no output fields are set

Reported by @dotJson in #3

I find if I dont set an output map in the batch dialog it does not iterate through the CSV so I have been selecting bogus fields to get it to go.
if it, as you say should work without defining an output, then something is stopping my runners after the first iteration. I have been setting it to some random selection in the CSV headers and typing garbage in the JSON path field to get it to go.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.