Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more snippets for the post-request scripting #7395

Merged
merged 1 commit into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ const updateRequestAuth =
);`;
const requireAModule = "const atob = require('atob');";

const getStatusCode = 'const statusCode = insomnia.response.code;';
const getStatusMsg = 'const status = insomnia.response.status;';
const getRespTime = 'const responseTime = insomnia.response.responseTime;';
const getJsonBody = 'const jsonBody = insomnia.response.json();';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these sync functions or should we await them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing it out, I verified that they are sync functions.

const getTextBody = 'const textBody = insomnia.response.text();';
const findHeader =
`const header = insomnia.response.headers.find(
header => header.key === 'Content-Type',
{},
);`;
const getCookies = 'const cookies = insomnia.response.cookies.toObject();';

const lintOptions = {
globals: {
// https://jshint.com/docs/options/
Expand Down Expand Up @@ -380,6 +392,70 @@ export const RequestScriptEditor: FC<Props> = ({
/>
</DropdownItem>
</Dropdown>

<Dropdown
aria-label='Response Handling'
placement='top left'
triggerButton={
<DropdownButton>
<ItemContent
icon="code"
label='Response Handling'
/>
</DropdownButton>
}
>
<DropdownItem textValue='Get status code' arial-label={'Get status code'}>
<ItemContent
icon="circle-info"
label='Get status code'
onClick={() => addSnippet(getStatusCode)}
/>
</DropdownItem>
<DropdownItem textValue='Get status message' arial-label={'Get status message'}>
<ItemContent
icon="circle-info"
label='Get status message'
onClick={() => addSnippet(getStatusMsg)}
/>
</DropdownItem>
<DropdownItem textValue='Get response time' arial-label={'Get response time'}>
<ItemContent
icon="circle-info"
label='Get response time'
onClick={() => addSnippet(getRespTime)}
/>
</DropdownItem>
<DropdownItem textValue='Get body as JSON' arial-label={'Get body as JSON'}>
<ItemContent
icon="circle-info"
label='Get body as JSON'
onClick={() => addSnippet(getJsonBody)}
/>
</DropdownItem>
<DropdownItem textValue='Get body as text' arial-label={'Get body as text'}>
<ItemContent
icon="circle-info"
label='Get body as text'
onClick={() => addSnippet(getTextBody)}
/>
</DropdownItem>
<DropdownItem textValue='Find a header by name' arial-label={'Find a header by name'}>
<ItemContent
icon="circle-info"
label='Find a header by name'
onClick={() => addSnippet(findHeader)}
/>
</DropdownItem>
<DropdownItem textValue='Get cookies' arial-label={'Get cookies'}>
<ItemContent
icon="circle-info"
label='Get cookies'
onClick={() => addSnippet(getCookies)}
/>
</DropdownItem>
</Dropdown>

<Dropdown
aria-label='Misc'
placement='top left'
Expand Down
Loading