From 0193541ac0bb9a2361d6c0ab2857859c02b6b3a0 Mon Sep 17 00:00:00 2001 From: DraGun64 Date: Tue, 1 Apr 2025 16:44:05 +0200 Subject: [PATCH 1/3] add http-caller example --- http-caller/index.ts | 49 +++++++++++++++++++++++++++++++++++++++ http-caller/packages.json | 8 +++++++ 2 files changed, 57 insertions(+) create mode 100644 http-caller/index.ts create mode 100644 http-caller/packages.json diff --git a/http-caller/index.ts b/http-caller/index.ts new file mode 100644 index 0000000..5a273a6 --- /dev/null +++ b/http-caller/index.ts @@ -0,0 +1,49 @@ +export function getDescription() { + return { + description: "HttpCaller", + input: [ + { + id: "get", + displayName: "URL GET", + description: "URL to call - method GET", + type: "InputResource", + }, + { + id: "post", + displayName: "URL POST", + description: "URL to call - method POST", + type: "OutputResource", + }, + ], + output: [], + } as const satisfies ScriptDescription; +} + +export async function execute(context) { + // METHOD GET + console.log("✅ URL GET: " + context.parameters.get); + + const getEndpoint = context.parameters.get; + const getResponse = await fetch(getEndpoint); + const getJson = await getResponse.json(); + console.debug(getJson); + + // METHOD POST + console.log("✅ URL POST: " + context.parameters.post); + + const headers = new Headers(); + headers.append("Content-Type", "application/json"); + headers.append("Accept", "application/json"); + const body = `{ "id": 78912 }`; + + const requestOptions = { + headers: headers, + method: "POST", + body: body, + }; + + const postEndpoint = context.parameters.post; + const postResponse = await fetch(postEndpoint, requestOptions); + const postJson = await postResponse.json(); + console.debug(postJson); +} \ No newline at end of file diff --git a/http-caller/packages.json b/http-caller/packages.json new file mode 100644 index 0000000..7cfb5db --- /dev/null +++ b/http-caller/packages.json @@ -0,0 +1,8 @@ +{ + "name": "http-caller", + "displayName": "HTTP Caller", + "description": "Provides an example of a GET and 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 + } \ No newline at end of file From ff18e2e084da42f522c0e0b436c3e3a8ab84d9b8 Mon Sep 17 00:00:00 2001 From: DraGun64 Date: Mon, 28 Apr 2025 14:44:52 +0200 Subject: [PATCH 2/3] type connector, separate examples connector type added get and post in separate examples --- http-caller-get/index.ts | 20 ++++++++++++++ http-caller-get/package.json | 8 ++++++ http-caller-post/index.ts | 32 +++++++++++++++++++++++ http-caller-post/package.json | 8 ++++++ http-caller/index.ts | 49 ----------------------------------- http-caller/packages.json | 8 ------ 6 files changed, 68 insertions(+), 57 deletions(-) create mode 100644 http-caller-get/index.ts create mode 100644 http-caller-get/package.json create mode 100644 http-caller-post/index.ts create mode 100644 http-caller-post/package.json delete mode 100644 http-caller/index.ts delete mode 100644 http-caller/packages.json 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..0612c9b --- /dev/null +++ b/http-caller-post/index.ts @@ -0,0 +1,32 @@ +export function getDescription() { + return { + description: "HTTP Caller POST", + input: [ + { + id: "post", + displayName: "URL POST", + description: "URL to call - method POST", + type: "Connector", + }, + ], + 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 = `{ "id": 78912 }`; + + 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 +} diff --git a/http-caller/index.ts b/http-caller/index.ts deleted file mode 100644 index 5a273a6..0000000 --- a/http-caller/index.ts +++ /dev/null @@ -1,49 +0,0 @@ -export function getDescription() { - return { - description: "HttpCaller", - input: [ - { - id: "get", - displayName: "URL GET", - description: "URL to call - method GET", - type: "InputResource", - }, - { - id: "post", - displayName: "URL POST", - description: "URL to call - method POST", - type: "OutputResource", - }, - ], - output: [], - } as const satisfies ScriptDescription; -} - -export async function execute(context) { - // METHOD GET - console.log("✅ URL GET: " + context.parameters.get); - - const getEndpoint = context.parameters.get; - const getResponse = await fetch(getEndpoint); - const getJson = await getResponse.json(); - console.debug(getJson); - - // METHOD POST - console.log("✅ URL POST: " + context.parameters.post); - - const headers = new Headers(); - headers.append("Content-Type", "application/json"); - headers.append("Accept", "application/json"); - const body = `{ "id": 78912 }`; - - const requestOptions = { - headers: headers, - method: "POST", - body: body, - }; - - const postEndpoint = context.parameters.post; - const postResponse = await fetch(postEndpoint, requestOptions); - const postJson = await postResponse.json(); - console.debug(postJson); -} \ No newline at end of file diff --git a/http-caller/packages.json b/http-caller/packages.json deleted file mode 100644 index 7cfb5db..0000000 --- a/http-caller/packages.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "http-caller", - "displayName": "HTTP Caller", - "description": "Provides an example of a GET and 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 - } \ No newline at end of file From b71cf41db9a034bb77e85120eac43a002043deb5 Mon Sep 17 00:00:00 2001 From: DraGun64 Date: Mon, 28 Apr 2025 15:24:48 +0200 Subject: [PATCH 3/3] variable body adding a string parameter to make the body variable --- http-caller-post/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/http-caller-post/index.ts b/http-caller-post/index.ts index 0612c9b..528c0e2 100644 --- a/http-caller-post/index.ts +++ b/http-caller-post/index.ts @@ -8,6 +8,12 @@ export function getDescription() { 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; @@ -17,7 +23,7 @@ export async function execute(context): Promise { const headers = new Headers(); headers.append("Content-Type", "application/json"); headers.append("Accept", "application/json"); - const body = `{ "id": 78912 }`; + const body = context.parameters.body; const requestOptions = { headers: headers,