okdv / insomnia-plugin-copy-path

Automatically copy response data based on its path in Insomnia REST Client. Use a request header to specify the respective XPath or JSONPath.
MIT License
0 stars 0 forks source link

insomnia-plugin-copy-path

Automatically copy response data based on its path in Insomnia REST Client. Use a request header to specify the respective XPath or JSONPath.

Installation

From Insomnia Plugin Hub

  1. Navigate to https://insomnia.rest/plugins/insomnia-plugin-copy-path
  2. Click Install Plugin
  3. Click Open
  4. Once opened, click Install

From the Insomnia App

  1. Go to Application > Preferences or click the cog icon (⚙️)
  2. Navigate to the Plugins tab
  3. Enter insomnia-plugin-copy-path
  4. Click Install

Manual Install

  1. Using a terminal, cd into your Insomnia plugins folder - see Insomnia Docs
  2. Run git clone https://github.com/okdv/insomnia-plugin-copy-path.git
  3. Run cd insomnia-plugin-copy-path

Usage

To activate this plugin on a request, include a header named copy-path and simply set its value to the desired XPath or JSONPath. For example, copy-path: //foo or copy-path: $..foo.

Options

There are a few options available to make the copy method more intuitive, none are required. These options can be included anywhere in the header name after copy-path. For example, copy-path --optionA --optionB or copy-path--option.

--option-name - Eligible Paths - Default : Description | Example

Examples

header

response

matched, copied value

XPath

Default

copy-path : //bar

<?xml version="1.0"?>
<foo>
   <bar>Hello</bar>
   <bar>World</bar>
</foo>

["Hello", "World"]

With Options

copy-path --first --outer: /foo/bar

<?xml version="1.0"?>
<foo>
   <bar>Hello</bar>
   <bar>World</bar>
</foo>

["Hello", "World"]

JSONPath

Default

copy-path : $.foo

{
  "foo": "Hello",
  "foobar": ["Hello","World"],
  "bar": {
    "foo": "World",
  }
}

["Hello"]

With Options

copy-path--last : $..foo

{
  "foo": "Hello",
  "foobar": ["Hello","World"],
  "bar": {
    "foo": "World",
  }
}

["Hello","World"]

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT