From 5dcfa66c5da2c0bf5ddf30e6213cd23ab8b1c0e6 Mon Sep 17 00:00:00 2001 From: Manda Putra Date: Sun, 3 Oct 2021 08:49:33 +0700 Subject: [PATCH] fix: parsing --- packages/hoppscotch-app/helpers/RESTExtURLParams.ts | 4 ++++ packages/hoppscotch-app/pages/index.vue | 9 ++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/hoppscotch-app/helpers/RESTExtURLParams.ts b/packages/hoppscotch-app/helpers/RESTExtURLParams.ts index 1746bf197..9b75a6690 100644 --- a/packages/hoppscotch-app/helpers/RESTExtURLParams.ts +++ b/packages/hoppscotch-app/helpers/RESTExtURLParams.ts @@ -109,5 +109,9 @@ function parseV1ExtURL(urlParams: Record): HoppRESTRequest { resolvedReq.endpoint = urlParams.endpoint } + if (urlParams.body && typeof urlParams.body === "string") { + resolvedReq.body = JSON.parse(urlParams.body) + } + return resolvedReq } diff --git a/packages/hoppscotch-app/pages/index.vue b/packages/hoppscotch-app/pages/index.vue index 33453d804..fa93b3d2b 100644 --- a/packages/hoppscotch-app/pages/index.vue +++ b/packages/hoppscotch-app/pages/index.vue @@ -164,15 +164,14 @@ function bindRequestToURLParams() { return filtered.length > 0 ? JSON.stringify(filtered) : null }) - const contentType = request.value.body.contentType - const body = computed(() => { + const contentType = request.value.body.contentType if (contentType === "multipart/form-data") { const body = request.value.body.body as FormDataKeyValue[] const filtered = body.filter((x) => x.key !== "") - return filtered.length > 0 ? JSON.stringify(filtered) : null + return JSON.stringify({ body: filtered, contentType }) } - return JSON.stringify(request.value.body) + return JSON.stringify({ body: request.value.body.body, contentType }) }) // Combine them together to a cleaner value @@ -182,7 +181,7 @@ function bindRequestToURLParams() { endpoint: request.value.endpoint, headers: headers.value, params: params.value, - body: JSON.stringify({ contentType, body }), + body: body.value, })) // Watch and update accordingly