Skip to content

Instantly share code, notes, and snippets.

@cdreier
Last active January 20, 2025 14:23
Show Gist options
  • Save cdreier/89b9f52db2ba7bb13087d0f6f181062a to your computer and use it in GitHub Desktop.
Save cdreier/89b9f52db2ba7bb13087d0f6f181062a to your computer and use it in GitHub Desktop.
Insomnia: looped requests
// For help writing plugins, visit the documentation to get started:
// https://docs.insomnia.rest/insomnia/introduction-to-plugins
var dataIndex = 0;
var dataSize = 0;
var codes = [];
module.exports.requestActions = [
{
label: "Loop Request",
action: async (context, data) => {
const { request } = data;
dataIndex = 0;
for (dataIndex; dataIndex < dataSize; dataIndex++) {
const newRequest = {
...request,
}
console.log(request)
const response = await context.network.sendRequest(newRequest);
console.log(response)
codes.push(`${response.statusCode}`);
codes.push(`<br />`);
}
dataIndex = 0;
const html = `<code style="width: 100%;">${dataIndex} - ${dataSize} <br/><br/> ${codes.join(" ")}</code>`;
codes = [];
context.app.showGenericModalDialog("Results", { html });
},
},
];
module.exports.templateTags = [{
name: 'loopData',
displayName: 'Loop Data',
description: 'a json list to loop over in this place',
args: [
{
displayName: 'Data',
description: 'Loop Data',
type: 'string',
defaultValue: "[]"
}
],
async run(context, data) {
const list = JSON.parse(data)
dataSize = list.length
const oldIndex = dataIndex
codes.push(`loop val: ${list[oldIndex]} ->`);
// TODO check if index is out of bounds
return list[oldIndex]
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment