feat(http-request): introduce custom request action

This commit is contained in:
Ali BARIN
2023-02-02 22:30:07 +00:00
parent f98c797311
commit 2f64a074c6
5 changed files with 80 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
import defineAction from '../../../../helpers/define-action';
type TMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
export default defineAction({
name: 'Custom Request',
key: 'customRequest',
description: 'Makes a custom HTTP request by providing raw details.',
arguments: [
{
label: 'Method',
key: 'method',
type: 'dropdown' as const,
required: true,
description:
`The HTTP method we'll use to perform the request.`,
value: 'GET',
options: [
{ label: 'DELETE', value: 'DELETE' },
{ label: 'GET', value: 'GET' },
{ label: 'PATCH', value: 'PATCH' },
{ label: 'POST', value: 'POST' },
{ label: 'PUT', value: 'PUT' },
]
},
{
label: 'URL',
key: 'url',
type: 'string' as const,
required: true,
description: 'Any URL with a querystring will be re-encoded properly.',
variables: true,
},
{
label: 'Data',
key: 'data',
type: 'string' as const,
required: true,
description: 'Place raw JSON data here.',
variables: true,
},
],
async run($) {
const method = $.step.parameters.method as TMethod;
const data = $.step.parameters.data as string;
const url = $.step.parameters.url as string;
const response = await $.http.request(
{
url,
method,
data,
headers: {
'Content-Type': 'application/json'
}
}
);
$.setActionItem({ raw: response.data });
},
});