Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
<template>
<AppPaneLayout layout-id="rest-primary">
<template #primary>
<HttpExampleResponseRequest v-model="tab" />
<HttpRequestOptions
v-model="tab.document.response.originalRequest"
v-model:option-tab="optionTabPreference"
v-model:inherited-properties="tab.document.inheritedProperties"
:envs="resolvedEnvs"
/>
</template>
<template #secondary>
<HttpExampleResponse
v-model:document="tab.document"
:is-embed="false"
:tab-id="tab.id"
/>
</template>
</AppPaneLayout>
</template>
<script setup lang="ts">
import { watch, ref, computed } from "vue"
import { useVModel } from "@vueuse/core"
import { cloneDeep, isEqual } from "lodash-es"
import { HoppTab } from "~/services/tab"
import { HoppSavedExampleDocument } from "~/helpers/tab/document"
import { RESTOptionTabs } from "../RequestOptions.vue"
import { useReadonlyStream } from "@composables/stream"
import {
aggregateEnvsWithCurrentValue$,
getAggregateEnvsWithCurrentValue,
} from "~/newstore/environments"
import { getEffectiveVariablesForRequest } from "~/helpers/utils/environments"
const props = defineProps<{ modelValue: HoppTab<HoppSavedExampleDocument> }>()
const emit = defineEmits<{
(e: "update:modelValue", val: HoppTab<HoppSavedExampleDocument>): void
}>()
const tab = useVModel(props, "modelValue", emit)
const optionTabPreference = ref<RESTOptionTabs>("params")
const envs = useReadonlyStream(
aggregateEnvsWithCurrentValue$,
getAggregateEnvsWithCurrentValue()
)
const resolvedEnvs = computed(() => {
// `showSecretCollectionValues = false` keeps inherited collection secrets
// masked in this display list, matching the other display/preview consumers.
// Execution/resolution callers (codegen, auth request builder) keep the
// default `true` because they need the resolved value, not a mask.
return getEffectiveVariablesForRequest(
tab.value.document.response.originalRequest.requestVariables,
tab.value.document.inheritedProperties?.variables,
envs.value,
false
)
})
// TODO: Come up with a better dirty check
let oldResponse = cloneDeep(tab.value.document.response)
watch(
() => tab.value.document.response,
(updatedValue) => {
if (!tab.value.document.isDirty && !isEqual(oldResponse, updatedValue)) {
tab.value.document.isDirty = true
}
oldResponse = cloneDeep(updatedValue)
},
{ deep: true }
)
</script>