nlink-community-http-request 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/definition.json +307 -0
- package/execution.js +118 -0
- package/icon.svg +1 -0
- package/package.json +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# nLink Community Node: HTTP Request
|
|
2
|
+
|
|
3
|
+
Provides the ability to execute API Requests over HTTP/HTTPS protocols with common methods (GET, POST, PUT, DELETE, PATCH).
|
|
4
|
+
|
|
5
|
+
## Identity
|
|
6
|
+
- **Node name**: `nlink-community.httpRequest`
|
|
7
|
+
- **Group**: `community`, `network`
|
|
8
|
+
|
|
9
|
+
## Installation and Usage
|
|
10
|
+
This package is built specifically for the nLink Workflow Platform. When published to NPM, nLink Core can automatically download and activate this node.
|
package/definition.json
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nlink-community.httpRequest",
|
|
3
|
+
"displayName": "HTTP Request (Community)",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "Makes an HTTP request with configurable method and URL",
|
|
6
|
+
"group": [
|
|
7
|
+
"community",
|
|
8
|
+
"network"
|
|
9
|
+
],
|
|
10
|
+
"inputs": [
|
|
11
|
+
"main"
|
|
12
|
+
],
|
|
13
|
+
"outputs": [
|
|
14
|
+
"main"
|
|
15
|
+
],
|
|
16
|
+
"icon": "/static/nodes/nlink-community.httpRequest/icon.svg",
|
|
17
|
+
"credentialTypes": [
|
|
18
|
+
"nlink-credential.basicAuth",
|
|
19
|
+
"nlink-credential.headerAuth",
|
|
20
|
+
"nlink-credential.jwtAuth"
|
|
21
|
+
],
|
|
22
|
+
"properties": [
|
|
23
|
+
{
|
|
24
|
+
"displayName": "URL",
|
|
25
|
+
"name": "url",
|
|
26
|
+
"type": "string",
|
|
27
|
+
"required": true,
|
|
28
|
+
"placeholder": "https://api.example.com/data"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"displayName": "Method",
|
|
32
|
+
"name": "method",
|
|
33
|
+
"type": "options",
|
|
34
|
+
"default": "GET",
|
|
35
|
+
"options": [
|
|
36
|
+
{
|
|
37
|
+
"name": "GET",
|
|
38
|
+
"displayName": "GET",
|
|
39
|
+
"value": "GET"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "POST",
|
|
43
|
+
"displayName": "POST",
|
|
44
|
+
"value": "POST"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "PUT",
|
|
48
|
+
"displayName": "PUT",
|
|
49
|
+
"value": "PUT"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"name": "DELETE",
|
|
53
|
+
"displayName": "DELETE",
|
|
54
|
+
"value": "DELETE"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "PATCH",
|
|
58
|
+
"displayName": "PATCH",
|
|
59
|
+
"value": "PATCH"
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"displayName": "Send Headers",
|
|
65
|
+
"name": "sendHeaders",
|
|
66
|
+
"type": "boolean",
|
|
67
|
+
"default": false
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"displayName": "Headers Input Type",
|
|
71
|
+
"name": "headersInputType",
|
|
72
|
+
"type": "options",
|
|
73
|
+
"default": "json",
|
|
74
|
+
"options": [
|
|
75
|
+
{
|
|
76
|
+
"name": "json",
|
|
77
|
+
"displayName": "JSON",
|
|
78
|
+
"value": "json"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"name": "params",
|
|
82
|
+
"displayName": "Params",
|
|
83
|
+
"value": "params"
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"displayOptions": {
|
|
87
|
+
"show": {
|
|
88
|
+
"sendHeaders": [
|
|
89
|
+
true
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"displayName": "Headers (JSON)",
|
|
96
|
+
"name": "headersJson",
|
|
97
|
+
"type": "string",
|
|
98
|
+
"default": "{}",
|
|
99
|
+
"placeholder": "{\"Authorization\": \"Bearer token\"}",
|
|
100
|
+
"description": "HTTP headers as a JSON object",
|
|
101
|
+
"displayOptions": {
|
|
102
|
+
"show": {
|
|
103
|
+
"sendHeaders": [
|
|
104
|
+
true
|
|
105
|
+
],
|
|
106
|
+
"headersInputType": [
|
|
107
|
+
"json"
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"typeOptions": {
|
|
112
|
+
"rows": 2
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"displayName": "Headers",
|
|
117
|
+
"name": "headersParams",
|
|
118
|
+
"type": "collection",
|
|
119
|
+
"default": [
|
|
120
|
+
{
|
|
121
|
+
"key": "",
|
|
122
|
+
"value": ""
|
|
123
|
+
}
|
|
124
|
+
],
|
|
125
|
+
"description": "HTTP headers as key-value pairs",
|
|
126
|
+
"typeOptions": {
|
|
127
|
+
"multipleValues": true
|
|
128
|
+
},
|
|
129
|
+
"displayOptions": {
|
|
130
|
+
"show": {
|
|
131
|
+
"sendHeaders": [
|
|
132
|
+
true
|
|
133
|
+
],
|
|
134
|
+
"headersInputType": [
|
|
135
|
+
"params"
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"displayName": "Send Query",
|
|
142
|
+
"name": "sendQuery",
|
|
143
|
+
"type": "boolean",
|
|
144
|
+
"default": false
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"displayName": "Query Input Type",
|
|
148
|
+
"name": "queryInputType",
|
|
149
|
+
"type": "options",
|
|
150
|
+
"default": "params",
|
|
151
|
+
"options": [
|
|
152
|
+
{
|
|
153
|
+
"name": "json",
|
|
154
|
+
"displayName": "JSON",
|
|
155
|
+
"value": "json"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"name": "params",
|
|
159
|
+
"displayName": "Params",
|
|
160
|
+
"value": "params"
|
|
161
|
+
}
|
|
162
|
+
],
|
|
163
|
+
"displayOptions": {
|
|
164
|
+
"show": {
|
|
165
|
+
"sendQuery": [
|
|
166
|
+
true
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"displayName": "Query (JSON)",
|
|
173
|
+
"name": "queryJson",
|
|
174
|
+
"type": "string",
|
|
175
|
+
"default": "{}",
|
|
176
|
+
"placeholder": "{\"page\": \"1\", \"limit\": \"10\"}",
|
|
177
|
+
"description": "Query parameters as a JSON object",
|
|
178
|
+
"displayOptions": {
|
|
179
|
+
"show": {
|
|
180
|
+
"sendQuery": [
|
|
181
|
+
true
|
|
182
|
+
],
|
|
183
|
+
"queryInputType": [
|
|
184
|
+
"json"
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
"typeOptions": {
|
|
189
|
+
"rows": 2
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"displayName": "Query Parameters",
|
|
194
|
+
"name": "queryParams",
|
|
195
|
+
"type": "collection",
|
|
196
|
+
"default": [
|
|
197
|
+
{
|
|
198
|
+
"key": "",
|
|
199
|
+
"value": ""
|
|
200
|
+
}
|
|
201
|
+
],
|
|
202
|
+
"description": "URL query parameters as key-value pairs",
|
|
203
|
+
"typeOptions": {
|
|
204
|
+
"multipleValues": true
|
|
205
|
+
},
|
|
206
|
+
"displayOptions": {
|
|
207
|
+
"show": {
|
|
208
|
+
"sendQuery": [
|
|
209
|
+
true
|
|
210
|
+
],
|
|
211
|
+
"queryInputType": [
|
|
212
|
+
"params"
|
|
213
|
+
]
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"displayName": "Send Body",
|
|
219
|
+
"name": "sendBody",
|
|
220
|
+
"type": "boolean",
|
|
221
|
+
"default": false
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"displayName": "Body Input Type",
|
|
225
|
+
"name": "bodyInputType",
|
|
226
|
+
"type": "options",
|
|
227
|
+
"default": "json",
|
|
228
|
+
"options": [
|
|
229
|
+
{
|
|
230
|
+
"name": "json",
|
|
231
|
+
"displayName": "JSON",
|
|
232
|
+
"value": "json"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"name": "params",
|
|
236
|
+
"displayName": "Params",
|
|
237
|
+
"value": "params"
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
"displayOptions": {
|
|
241
|
+
"show": {
|
|
242
|
+
"sendBody": [
|
|
243
|
+
true
|
|
244
|
+
]
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
"displayName": "Body (JSON)",
|
|
250
|
+
"name": "body",
|
|
251
|
+
"type": "string",
|
|
252
|
+
"default": "{}",
|
|
253
|
+
"placeholder": "{\"key\": \"value\"}",
|
|
254
|
+
"description": "Request body as a JSON string",
|
|
255
|
+
"displayOptions": {
|
|
256
|
+
"show": {
|
|
257
|
+
"sendBody": [
|
|
258
|
+
true
|
|
259
|
+
],
|
|
260
|
+
"bodyInputType": [
|
|
261
|
+
"json"
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
"typeOptions": {
|
|
266
|
+
"rows": 2
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"displayName": "Body Parameters",
|
|
271
|
+
"name": "bodyParams",
|
|
272
|
+
"type": "collection",
|
|
273
|
+
"default": [
|
|
274
|
+
{
|
|
275
|
+
"key": "",
|
|
276
|
+
"value": ""
|
|
277
|
+
}
|
|
278
|
+
],
|
|
279
|
+
"description": "Request body as key-value pairs",
|
|
280
|
+
"typeOptions": {
|
|
281
|
+
"multipleValues": true
|
|
282
|
+
},
|
|
283
|
+
"displayOptions": {
|
|
284
|
+
"show": {
|
|
285
|
+
"sendBody": [
|
|
286
|
+
true
|
|
287
|
+
],
|
|
288
|
+
"bodyInputType": [
|
|
289
|
+
"params"
|
|
290
|
+
]
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
"displayName": "Disabled",
|
|
296
|
+
"name": "disabled",
|
|
297
|
+
"type": "boolean",
|
|
298
|
+
"default": false
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
"displayName": "Execute Once",
|
|
302
|
+
"name": "executeOnce",
|
|
303
|
+
"type": "boolean",
|
|
304
|
+
"default": false
|
|
305
|
+
}
|
|
306
|
+
]
|
|
307
|
+
}
|
package/execution.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
var url = params.url;
|
|
2
|
+
if (!url) {
|
|
3
|
+
throw "URL is required";
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
var method = params.method || 'GET';
|
|
7
|
+
|
|
8
|
+
// 1. Query Params
|
|
9
|
+
if (params.sendQuery) {
|
|
10
|
+
var queryString = [];
|
|
11
|
+
if (params.queryInputType === 'json') {
|
|
12
|
+
var qMap = {};
|
|
13
|
+
if (typeof params.queryJson === 'string' && params.queryJson) {
|
|
14
|
+
try { qMap = JSON.parse(params.queryJson); } catch (e) { }
|
|
15
|
+
} else if (typeof params.queryJson === 'object' && params.queryJson) {
|
|
16
|
+
qMap = params.queryJson;
|
|
17
|
+
}
|
|
18
|
+
for (var k in qMap) {
|
|
19
|
+
queryString.push(encodeURIComponent(k) + '=' + encodeURIComponent(qMap[k]));
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
if (Array.isArray(params.queryParams)) {
|
|
23
|
+
for (var i = 0; i < params.queryParams.length; i++) {
|
|
24
|
+
var item = params.queryParams[i];
|
|
25
|
+
if (item && item.key) {
|
|
26
|
+
queryString.push(encodeURIComponent(item.key) + '=' + encodeURIComponent(item.value || ''));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (queryString.length > 0) {
|
|
32
|
+
var separator = url.indexOf('?') === -1 ? '?' : '&';
|
|
33
|
+
url += separator + queryString.join('&');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 2. Headers
|
|
38
|
+
var headers = {};
|
|
39
|
+
if (params.sendHeaders) {
|
|
40
|
+
if (params.headersInputType === 'json') {
|
|
41
|
+
var hMap = {};
|
|
42
|
+
if (typeof params.headersJson === 'string' && params.headersJson) {
|
|
43
|
+
try { hMap = JSON.parse(params.headersJson); } catch (e) { }
|
|
44
|
+
} else if (typeof params.headersJson === 'object' && params.headersJson) {
|
|
45
|
+
hMap = params.headersJson;
|
|
46
|
+
}
|
|
47
|
+
for (var k in hMap) {
|
|
48
|
+
headers[k] = hMap[k];
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
if (Array.isArray(params.headersParams)) {
|
|
52
|
+
for (var i = 0; i < params.headersParams.length; i++) {
|
|
53
|
+
var item = params.headersParams[i];
|
|
54
|
+
if (item && item.key) {
|
|
55
|
+
headers[item.key] = item.value || '';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 3. Body
|
|
63
|
+
var body = null;
|
|
64
|
+
if (params.sendBody) {
|
|
65
|
+
if (params.bodyInputType === 'params') {
|
|
66
|
+
var parts = [];
|
|
67
|
+
if (Array.isArray(params.bodyParams)) {
|
|
68
|
+
for (var i = 0; i < params.bodyParams.length; i++) {
|
|
69
|
+
var item = params.bodyParams[i];
|
|
70
|
+
if (item && item.key) {
|
|
71
|
+
parts.push(encodeURIComponent(item.key) + '=' + encodeURIComponent(item.value || ''));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
body = parts.join('&');
|
|
76
|
+
if (!headers["Content-Type"]) headers["Content-Type"] = "application/x-www-form-urlencoded";
|
|
77
|
+
} else {
|
|
78
|
+
if (typeof params.body === 'object' && params.body !== null) {
|
|
79
|
+
body = JSON.stringify(params.body);
|
|
80
|
+
} else if (typeof params.body === 'string' && params.body.trim() !== '') {
|
|
81
|
+
body = params.body;
|
|
82
|
+
} else {
|
|
83
|
+
body = "{}";
|
|
84
|
+
}
|
|
85
|
+
if (!headers["Content-Type"]) headers["Content-Type"] = "application/json";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
var resp;
|
|
90
|
+
if (http.request) {
|
|
91
|
+
resp = http.request(method, url, body, headers);
|
|
92
|
+
} else if (method === 'GET' && http.get) {
|
|
93
|
+
resp = http.get(url);
|
|
94
|
+
} else if (method === 'POST' && http.post) {
|
|
95
|
+
resp = http.post(url, body, headers);
|
|
96
|
+
} else {
|
|
97
|
+
throw "http.request helper method is missing on the server. Please rebuild/restart backend.";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
var responseBody = resp.body;
|
|
101
|
+
var parsedData = null;
|
|
102
|
+
try {
|
|
103
|
+
parsedData = JSON.parse(responseBody);
|
|
104
|
+
} catch (e) {
|
|
105
|
+
parsedData = responseBody;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
$output = {
|
|
109
|
+
status: resp.status,
|
|
110
|
+
status_code: resp.status_code,
|
|
111
|
+
headers: resp.headers,
|
|
112
|
+
body: responseBody,
|
|
113
|
+
data: parsedData,
|
|
114
|
+
request: {
|
|
115
|
+
method: method,
|
|
116
|
+
url: url
|
|
117
|
+
}
|
|
118
|
+
};
|
package/icon.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 170"><path fill="#fcb400" d="M89 4.8 16.2 34.9c-4.1 1.7-4 7.4.1 9.1l73.2 29c6.4 2.6 13.6 2.6 20 0l73.2-29c4.1-1.6 4.1-7.4.1-9.1l-73-30.1C103.2 2 95.7 2 89 4.8"/><path fill="#18bfff" d="M105.9 88.9v72.5c0 3.4 3.5 5.8 6.7 4.5l81.6-31.7c1.9-.7 3.1-2.5 3.1-4.5V57.2c0-3.4-3.5-5.8-6.7-4.5L109 84.3c-1.9.8-3.1 2.6-3.1 4.6"/><path fill="#f82b60" d="m86.9 92.6-24.2 11.7-2.5 1.2L9.1 130c-3.2 1.6-7.4-.8-7.4-4.4V57.5c0-1.3.7-2.4 1.6-3.3q.6-.6 1.2-.9c1.2-.7 3-.9 4.4-.3l77.5 30.7c4 1.5 4.3 7.1.5 8.9"/><path fill="#ba1e45" d="m86.9 92.6-24.2 11.7-59.4-50q.6-.6 1.2-.9c1.2-.7 3-.9 4.4-.3l77.5 30.7c4 1.4 4.3 7 .5 8.8"/></svg>
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nlink-community-http-request",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "HTTP Request community node for nLink Workflow Platform",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nlink",
|
|
7
|
+
"nlink-nodes",
|
|
8
|
+
"community-nodes",
|
|
9
|
+
"http",
|
|
10
|
+
"workflow"
|
|
11
|
+
],
|
|
12
|
+
"author": "nLink",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"nlink": {
|
|
15
|
+
"nodes": [
|
|
16
|
+
"nlink-community.httpRequest"
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|