Skip to content

Commit f13b9ce

Browse files
committed
Compute variables in request body of request node
1 parent 4780061 commit f13b9ce

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

src/components/molecules/flow/graph/compute/requestnode.js

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,24 @@ const runHttpRequest = (request) => {
88
});
99
};
1010

11-
const formulateRequest = (node, finalUrl, auth, logs) => {
11+
const formulateRequest = (node, finalUrl, variablesDict, auth, logs) => {
1212
let restMethod = node.data.requestType.toLowerCase();
1313
let contentType = 'application/json';
1414
let requestData = undefined;
1515

16-
if (restMethod === 'get') {
17-
if (node.data.requestBody) {
18-
if (node.data.requestBody.type === 'raw-json') {
19-
contentType = 'application/json';
20-
requestData = node.data.requestBody.body ? JSON.parse(node.data.requestBody.body) : JSON.parse('{}');
21-
}
22-
}
23-
} else if (restMethod === 'post' || restMethod === 'put') {
24-
if (node.data.requestBody) {
25-
if (node.data.requestBody.type === 'form-data') {
26-
contentType = 'multipart/form-data';
27-
requestData = {
28-
key: node.data.requestBody.body.key,
29-
value: node.data.requestBody.body.value,
30-
name: node.data.requestBody.body.name,
31-
};
32-
} else if (node.data.requestBody.type === 'raw-json') {
33-
contentType = 'application/json';
34-
requestData = node.data.requestBody.body ? JSON.parse(node.data.requestBody.body) : JSON.parse('{}');
35-
}
16+
if (node.data.requestBody) {
17+
if (node.data.requestBody.type === 'raw-json') {
18+
contentType = 'application/json';
19+
requestData = node.data.requestBody.body
20+
? JSON.parse(computeVariables(node.data.requestBody.body, variablesDict))
21+
: JSON.parse('{}');
22+
} else if (node.data.requestBody.type === 'form-data') {
23+
contentType = 'multipart/form-data';
24+
requestData = {
25+
key: computeVariables(node.data.requestBody.body.key, variablesDict),
26+
value: node.data.requestBody.body.value,
27+
name: node.data.requestBody.body.name,
28+
};
3629
}
3730
}
3831

@@ -68,7 +61,7 @@ export const computeRequestNode = async (node, prevNodeOutputData, env, auth, lo
6861
const finalUrl = computeVariables(node.data.url, variablesDict);
6962

7063
// step 3
71-
const options = formulateRequest(node, finalUrl, auth, logs);
64+
const options = formulateRequest(node, finalUrl, variablesDict, auth, logs);
7265

7366
console.debug('Avialable variables: ', variablesDict);
7467
console.debug('Evaluated Url: ', finalUrl);

src/components/molecules/flow/nodes/RequestBody.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,7 @@ const RequestBody = ({ nodeData }) => {
148148
onChange={(e) => handleFormDataKey(e)}
149149
value={fileKey}
150150
/>
151-
<div className='px-4 py-2 border-l rounded-br-md rounded-tr-md border-l-neutral-500'>
152-
File
153-
</div>
151+
<div className='px-4 py-2 border-l rounded-br-md rounded-tr-md border-l-neutral-500'>File</div>
154152
</div>
155153
<div className='py-2'>
156154
<button
@@ -166,6 +164,7 @@ const RequestBody = ({ nodeData }) => {
166164
<input type='file' id='file' ref={uploadFileForRequestNode} onChange={handleFileUpload} />
167165
</div>
168166
</button>
167+
{fileName != '' ? fileName : 'Choose a file to upload'}
169168
</div>
170169
</div>
171170
)}

0 commit comments

Comments
 (0)