insomnia-plugin-utils
v1.0.3
Published
Create new functions from arguments passed as key and value or in generic format and generate the values in the result you want
Downloads
67
Maintainers
Readme
insomnia-plugin-utils
Create complex or simple functions for your data directly in the Insomnia REST Client!
This plugin is published in npm.
Installation
- Open Insomnia.
- Go to Insomnia > Preferences.
- Go to "Plugins" tab.
- Type "insomnia-plugin-utils" in the "Install Plugin" field.
- Click "Install Plugin".
Any questions about installing the plugin, go to Insomnia "Managing plugins" documentation.
Usage
Use Template Tags (i.e. CTRL + SPACE, then find "Utils - *") to add plugin types.
Examples
Random UUID
Random Amount (to use the
Random amount
type, you need to enter two fieldsmin
andmax
)
Creativity and Imagination
The
Random amount
type is an example of what can be created with this plugin, you can pass as manykey:value
as you need and assemble the return you want without having to do much.Structure of the types object.
{ type: string, displayName: string, liveDisplayName?: string, description?: string, method: (args) => expression, // Only type === 'enum' options: Array<{ { displayName: string, value: string } ] }
Example to add new basic type
- Open the file
types-method.js
. - Look up for the variable
typesMethod
. - You can follow the pattern of insomnia doc itself or duplicate existing types except
Random amount
.
Example to add new complex type
Open the file
types-method.js
.Look up for the variable
typesMethod
.Now to create one more complex type like
Random amount
.Structure type
{ type: "string", displayName: "Random names", liveDisplayName: "Name", description: "Generate random names", defaultValue: "names: Philip,Luciana", method: (args) => random_names(args) }
Structure function
const random_names = (args) => { const value = getArgsValue(args) const keys = ["names"] let isValid = containsKeys(value, ...keys) if (!isValid.ok) { const errorMessage = `The input { ${value} } not contain all keys [${keys}] is missing ${isValid.missingKeys}` console.error(errorMessage) return errorMessage } const obj = toObject(value) names = obj.names.split(',') const random = Math.floor(Math.random() * names.length); return names[random] }