Automatically copy response data based on its path in Insomnia REST Client. Use a request header to specify the respective XPath or JSONPath.
insomnia-plugin-copy-path
cd
into your Insomnia plugins folder - see Insomnia Docsgit clone https://github.com/okdv/insomnia-plugin-copy-path.git
cd insomnia-plugin-copy-path
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
.
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
--first
- XPath / JSONPath : Return only the first match | [{"foo":"bar"},"foo",["bar"]]
--last
- XPath / JSONPath : Return only the last match | [1,2,3]
--all
- XPath / JSONPath - Default : Return only the last match | [1,2,3]
--outer
- XPath : Return includes XML tags |
--inner
- XPath - Default : Return includes XML tags |
header
response
matched, copied value
copy-path : //bar
<?xml version="1.0"?>
<foo>
<bar>Hello</bar>
<bar>World</bar>
</foo>
["Hello", "World"]
copy-path --first --outer: /foo/bar
<?xml version="1.0"?>
<foo>
<bar>Hello</bar>
<bar>World</bar>
</foo>
["
copy-path : $.foo
{
"foo": "Hello",
"foobar": ["Hello","World"],
"bar": {
"foo": "World",
}
}
["Hello"]
copy-path--last : $..foo
{
"foo": "Hello",
"foobar": ["Hello","World"],
"bar": {
"foo": "World",
}
}
["Hello","World"]
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.