Adding in the ability to retrieve and view the headers from a rest response.

This commit is contained in:
mike12345567 2021-12-09 12:30:05 +00:00
parent e1ae7c603d
commit ad1007ffdc
6 changed files with 49 additions and 12 deletions

View File

@ -1,12 +1,30 @@
<script>
import { Icon } from "@budibase/bbui"
import { Icon, Body } from "@budibase/bbui"
</script>
<a target="_blank" href="https://github.com/Budibase/budibase/discussions">
<Icon hoverable name="Help" size="XXL" />
<div class="inner hoverable">
<div class="hidden hoverable">
<Body size="S">Need help? Go to our forums</Body>
</div>
<Icon name="Help" size="XXL" />
</div>
</a>
<style>
.inner {
display: flex;
align-items: center;
gap: var(--spacing-s);
}
.inner :global(*) {
pointer-events: all;
transition: color var(--spectrum-global-animation-duration-100, 130ms);
}
.inner:hover :global(*) {
color: var(--spectrum-alias-icon-color-selected-hover);
cursor: pointer;
}
a {
color: inherit;
position: absolute;
@ -14,4 +32,10 @@
right: var(--spacing-m);
border-radius: 55%;
}
.hidden {
display: none;
}
.inner:hover .hidden {
display: block;
}
</style>

View File

@ -134,4 +134,7 @@
.container-active {
grid-template-columns: 1fr 1fr 50px 20px;
}
.readOnly {
grid-template-columns: 1fr 1fr;
}
</style>

View File

@ -266,7 +266,10 @@
/>
</Tab>
<Tab title="Raw">
<TextArea disabled value={response.raw} height="300" />
<TextArea disabled value={response.extra?.raw} height="300" />
</Tab>
<Tab title="Headers">
<KeyValueBuilder object={response.extra?.headers} readOnly />
</Tab>
<Tab title="Preview">
{#if response}

View File

@ -151,7 +151,7 @@ exports.preview = async function (ctx) {
const enrichedQuery = await enrichQueryFields(fields, parameters)
try {
const { rows, keys, info, raw } = await Runner.run({
const { rows, keys, info, extra } = await Runner.run({
datasource,
queryVerb,
query: enrichedQuery,
@ -162,7 +162,7 @@ exports.preview = async function (ctx) {
rows,
schemaFields: [...new Set(keys)],
info,
raw,
extra,
}
} catch (err) {
ctx.throw(400, err)

View File

@ -122,7 +122,7 @@ module RestModule {
}
async parseResponse(response: any) {
let data, raw
let data, raw, headers
const contentType = response.headers.get("content-type")
if (contentType && contentType.indexOf("application/json") !== -1) {
data = await response.json()
@ -133,6 +133,10 @@ module RestModule {
}
const size = formatBytes(response.headers.get("content-length") || 0)
const time = `${Math.round(performance.now() - this.startTimeMs)}ms`
headers = response.headers.raw()
for (let [key, value] of Object.entries(headers)) {
headers[key] = Array.isArray(value) ? value[0] : value
}
return {
data,
info: {
@ -140,7 +144,10 @@ module RestModule {
size,
time,
},
raw,
extra: {
raw,
headers,
},
}
}

View File

@ -19,8 +19,8 @@ function hasExtraData(response) {
return (
typeof response === "object" &&
!Array.isArray(response) &&
response.data &&
response.info
response.data != null &&
response.info != null
)
}
@ -34,11 +34,11 @@ async function runAndTransform(datasource, queryVerb, query, transformer) {
let output = formatResponse(await integration[queryVerb](query))
let rows = output,
info = undefined,
raw = undefined
extra = undefined
if (hasExtraData(output)) {
rows = output.data
info = output.info
raw = output.raw
extra = output.extra
}
// transform as required
@ -64,7 +64,7 @@ async function runAndTransform(datasource, queryVerb, query, transformer) {
integration.end()
}
return { rows, keys, info, raw }
return { rows, keys, info, extra }
}
module.exports = (input, callback) => {