Browse Source

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

master
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 = {}, let breakQs = {},
bindings = {} bindings = {}
let url = "" let url = ""
let saveId let saveId, isGet
let response, schema, enabledHeaders let response, schema, enabledHeaders
let datasourceType, integrationInfo, queryConfig, responseSuccess let datasourceType, integrationInfo, queryConfig, responseSuccess
@ -57,6 +57,7 @@
$: queryConfig = integrationInfo?.query $: queryConfig = integrationInfo?.query
$: url = buildUrl(url, breakQs) $: url = buildUrl(url, breakQs)
$: checkQueryName(url) $: checkQueryName(url)
$: isGet = query?.queryVerb === "read"
$: responseSuccess = $: responseSuccess =
response?.info?.code >= 200 && response?.info?.code <= 206 response?.info?.code >= 200 && response?.info?.code <= 206
@ -226,7 +227,7 @@
<Tab title="Body"> <Tab title="Body">
<RadioGroup <RadioGroup
bind:value={query.fields.bodyType} bind:value={query.fields.bodyType}
options={bodyTypes} options={isGet ? [bodyTypes[0]] : bodyTypes}
direction="horizontal" direction="horizontal"
getOptionLabel={option => option.name} getOptionLabel={option => option.name}
getOptionValue={option => option.value} 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 } const input: any = { method, headers: this.headers }
if (json && typeof json === "object" && Object.keys(json).length > 0) { if (requestBody) {
input.body = JSON.stringify(json) 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() this.startTimeMs = performance.now()

Loading…
Cancel
Save