Browse Source

Stopping get requests from having bodies (Node fetch doesn't allow this) and allow text body type.

pull/3785/head
mike12345567 5 years ago
parent
commit
ac49d718a4
  1. 5
      packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte
  2. 29
      packages/server/src/integrations/rest.ts

5
packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte

@ -48,7 +48,7 @@
let breakQs = {},
bindings = {}
let url = ""
let saveId
let saveId, isGet
let response, schema, enabledHeaders
let datasourceType, integrationInfo, queryConfig, responseSuccess
@ -57,6 +57,7 @@
$: queryConfig = integrationInfo?.query
$: url = buildUrl(url, breakQs)
$: checkQueryName(url)
$: isGet = query?.queryVerb === "read"
$: responseSuccess =
response?.info?.code >= 200 && response?.info?.code <= 206
@ -226,7 +227,7 @@
<Tab title="Body">
<RadioGroup
bind:value={query.fields.bodyType}
options={bodyTypes}
options={isGet ? [bodyTypes[0]] : bodyTypes}
direction="horizontal"
getOptionLabel={option => option.name}
getOptionValue={option => option.value}

29
packages/server/src/integrations/rest.ts

@ -162,18 +162,25 @@ module RestModule {
}
}
let json
if (bodyType === BodyTypes.JSON && requestBody) {
try {
json = JSON.parse(requestBody)
} catch (err) {
throw "Invalid JSON for request body"
}
}
const input: any = { method, headers: this.headers }
if (json && typeof json === "object" && Object.keys(json).length > 0) {
input.body = JSON.stringify(json)
if (requestBody) {
switch (bodyType) {
case BodyTypes.TEXT:
const text = typeof requestBody !== "string" ? JSON.stringify(requestBody) : requestBody
input.body = text
break
default: case BodyTypes.JSON:
try {
// confirm its json
const json = JSON.parse(requestBody)
if (json && typeof json === "object" && Object.keys(json).length > 0) {
input.body = requestBody
}
} catch (err) {
throw "Invalid JSON for request body"
}
break
}
}
this.startTimeMs = performance.now()

Loading…
Cancel
Save