diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte index 838646d806..d174770602 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte +++ b/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 @@ option.name} getOptionValue={option => option.value} diff --git a/packages/server/src/integrations/rest.ts b/packages/server/src/integrations/rest.ts index 10c2c1215b..582bbc5ad9 100644 --- a/packages/server/src/integrations/rest.ts +++ b/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()