diff --git a/http-caller-get/index.ts b/http-caller-get/index.ts new file mode 100644 index 0000000..5094d68 --- /dev/null +++ b/http-caller-get/index.ts @@ -0,0 +1,20 @@ +export function getDescription() { + return { + description: "HTTP Caller GET", + input: [ + { + id: "get", + displayName: "URL GET", + description: "URL to call - method GET", + type: "Connector", + }, + ], + output: [], + } as const satisfies ScriptDescription; +} + +export async function execute(context): Promise { + const requestEndpoint = context.parameters.get; + const response = await fetch(requestEndpoint); + console.debug(response.json()); +} diff --git a/http-caller-get/package.json b/http-caller-get/package.json new file mode 100644 index 0000000..dd34c16 --- /dev/null +++ b/http-caller-get/package.json @@ -0,0 +1,8 @@ +{ + "name": "http-caller-get", + "displayName": "HTTP Caller - GET request", + "description": "Provides an example of a GET request. Requires a Web endpoint type connector. WARNING: you have to either read the response body or close the connection because of the limitation of 6 outbound connections.", + "fromVersion": "23.08", + "toVersion": null, + "private": true +} diff --git a/http-caller-post/index.ts b/http-caller-post/index.ts new file mode 100644 index 0000000..528c0e2 --- /dev/null +++ b/http-caller-post/index.ts @@ -0,0 +1,38 @@ +export function getDescription() { + return { + description: "HTTP Caller POST", + input: [ + { + id: "post", + displayName: "URL POST", + description: "URL to call - method POST", + type: "Connector", + }, + { + id: "body", + displayName: "Body", + description: "Body to send to the endpoint", + type: "String", + } + ], + output: [], + } as const satisfies ScriptDescription; +} + +export async function execute(context): Promise { + const headers = new Headers(); + headers.append("Content-Type", "application/json"); + headers.append("Accept", "application/json"); + const body = context.parameters.body; + + const requestOptions = { + headers: headers, + method: "POST", + body: body, + }; + + const requestEndpoint = context.parameters.post; + const response = await fetch(requestEndpoint, requestOptions); + const responseJson = await response.json(); + console.debug(responseJson); +} diff --git a/http-caller-post/package.json b/http-caller-post/package.json new file mode 100644 index 0000000..c1e6a11 --- /dev/null +++ b/http-caller-post/package.json @@ -0,0 +1,8 @@ +{ + "name": "http-caller-post", + "displayName": "HTTP Caller - POST request", + "description": "Provides an example of a POST request. Requires a Web endpoint type connector. WARNING: you have to either read the response body or close the connection because of the limitation of 6 outbound connections.", + "fromVersion": "23.08", + "toVersion": null, + "private": true +}