diff --git a/assets/scss/themes.scss b/assets/scss/themes.scss
index 4ac55eab9..0641ba84a 100644
--- a/assets/scss/themes.scss
+++ b/assets/scss/themes.scss
@@ -28,7 +28,7 @@
// Tooltip color
--tooltip-color: theme("colors.dark.700");
// Editor theme
- --editor-theme: "twilight";
+ --editor-theme: "merbivore_soft";
}
@mixin lightTheme {
@@ -55,7 +55,7 @@
// Tooltip color
--tooltip-color: theme("colors.gray.50");
// Editor theme
- --editor-theme: "iplastic";
+ --editor-theme: "textmate";
}
@mixin blackTheme {
diff --git a/components/http/Headers.vue b/components/http/Headers.vue
index c3cd4be0e..0906f23ce 100644
--- a/components/http/Headers.vue
+++ b/components/http/Headers.vue
@@ -1,22 +1,27 @@
-
+
-
+
+
+
+
@@ -91,7 +97,7 @@
v-tippy="{ theme: 'tooltip' }"
:title="$t('delete')"
icon="delete"
- @click.native="removeRequestHeader(index)"
+ @click.native="deleteHeader(index)"
/>
@@ -99,46 +105,57 @@
diff --git a/components/http/Response.vue b/components/http/Response.vue
index dd90365a2..8b7ee49c2 100644
--- a/components/http/Response.vue
+++ b/components/http/Response.vue
@@ -1,22 +1,22 @@
-
-
-
-
+
+
diff --git a/components/smart/AutoComplete.vue b/components/smart/AutoComplete.vue
index 5967622ed..215c2ca87 100644
--- a/components/smart/AutoComplete.vue
+++ b/components/smart/AutoComplete.vue
@@ -22,6 +22,7 @@
@keyup="updateSuggestions"
@click="updateSuggestions"
@keydown="handleKeystroke"
+ @change="$emit('change', $event)"
/>
{{ tab.label }}
+
+ {{ tab.info }}
+
@@ -91,6 +94,20 @@ export default {
@apply focus:outline-none;
@apply relative;
+ .tab-info {
+ @apply inline-flex;
+ @apply items-center;
+ @apply justify-center;
+ @apply w-5;
+ @apply h-4;
+ @apply ml-2;
+ @apply text-8px;
+ @apply border border-divider;
+ @apply font-mono;
+ @apply rounded;
+ @apply text-secondaryLight;
+ }
+
&::after {
@apply absolute;
@apply inset-x-0;
@@ -110,6 +127,11 @@ export default {
@apply text-accent;
@apply border-accent;
+ .tab-info {
+ @apply text-secondary;
+ @apply border-dividerDark;
+ }
+
&::after {
@apply bg-accent;
}
diff --git a/helpers/lenses/lenses.js b/helpers/lenses/lenses.js
index a6fcd3313..f213ea9f2 100644
--- a/helpers/lenses/lenses.js
+++ b/helpers/lenses/lenses.js
@@ -7,13 +7,14 @@ import xmlLens from "./xmlLens"
export const lenses = [jsonLens, imageLens, htmlLens, xmlLens, rawLens]
export function getSuitableLenses(response) {
- if (!response || !response.headers || !response.headers["content-type"])
- return [rawLens]
+ const contentType = response.headers.find((h) => h.key === "content-type")
+ console.log(contentType)
+
+ if (!contentType) return [rawLens]
const result = []
for (const lens of lenses) {
- if (lens.isSupportedContentType(response.headers["content-type"]))
- result.push(lens)
+ if (lens.isSupportedContentType(contentType.value)) result.push(lens)
}
return result
diff --git a/helpers/network.js b/helpers/network.ts
similarity index 53%
rename from helpers/network.js
rename to helpers/network.ts
index ca291440e..887f902cd 100644
--- a/helpers/network.js
+++ b/helpers/network.ts
@@ -1,3 +1,4 @@
+import { BehaviorSubject, Observable } from "rxjs"
import AxiosStrategy, {
cancelRunningAxiosRequest,
} from "./strategies/AxiosStrategy"
@@ -5,6 +6,8 @@ import ExtensionStrategy, {
cancelRunningExtensionRequest,
hasExtensionInstalled,
} from "./strategies/ExtensionStrategy"
+import { HoppRESTResponse } from "./types/HoppRESTResponse"
+import { EffectiveHoppRESTRequest } from "./utils/EffectiveURL"
import { settingsStore } from "~/newstore/settings"
export const cancelRunningRequest = () => {
@@ -17,7 +20,7 @@ export const cancelRunningRequest = () => {
const isExtensionsAllowed = () => settingsStore.value.EXTENSIONS_ENABLED
-const runAppropriateStrategy = (req) => {
+const runAppropriateStrategy = (req: any) => {
if (isExtensionsAllowed() && hasExtensionInstalled()) {
return ExtensionStrategy(req)
}
@@ -41,5 +44,37 @@ export function getCurrentStrategyID() {
}
}
-export const sendNetworkRequest = (req) =>
+export const sendNetworkRequest = (req: any) =>
runAppropriateStrategy(req).finally(() => window.$nuxt.$loading.finish())
+
+export function createRESTNetworkRequestStream(
+ req: EffectiveHoppRESTRequest
+): Observable {
+ const response = new BehaviorSubject({ type: "loading" })
+
+ runAppropriateStrategy({
+ url: req.effectiveFinalURL,
+ }).then((res: any) => {
+ console.log(res)
+
+ const resObj: HoppRESTResponse = {
+ type: "success",
+ statusCode: res.status,
+ body: res.data,
+ headers: Object.keys(res.headers).map((x) => ({
+ key: x,
+ value: res.headers[x],
+ })),
+ meta: {
+ // TODO: Implement
+ responseSize: 0,
+ responseDuration: 0,
+ },
+ }
+ response.next(resObj)
+
+ response.complete()
+ })
+
+ return response
+}
diff --git a/helpers/types/HoppRESTResponse.ts b/helpers/types/HoppRESTResponse.ts
new file mode 100644
index 000000000..a6f8ec951
--- /dev/null
+++ b/helpers/types/HoppRESTResponse.ts
@@ -0,0 +1,22 @@
+export type HoppRESTResponse =
+ | { type: "loading" }
+ | {
+ type: "fail"
+ headers: { key: string; value: string }[]
+ body: ArrayBuffer
+ statusCode: number
+ }
+ | {
+ type: "network_fail"
+ error: Error
+ }
+ | {
+ type: "success"
+ headers: { key: string; value: string }[]
+ body: ArrayBuffer
+ statusCode: number
+ meta: {
+ responseSize: number // in bytes
+ responseDuration: number // in millis
+ }
+ }
diff --git a/helpers/utils/EffectiveURL.ts b/helpers/utils/EffectiveURL.ts
index 9ef9a6050..23089b769 100644
--- a/helpers/utils/EffectiveURL.ts
+++ b/helpers/utils/EffectiveURL.ts
@@ -3,7 +3,7 @@ import { map } from "rxjs/operators"
import { HoppRESTRequest } from "../types/HoppRESTRequest"
import { Environment } from "~/newstore/environments"
-interface EffectiveHoppRESTRequest extends HoppRESTRequest {
+export interface EffectiveHoppRESTRequest extends HoppRESTRequest {
/**
* The effective final URL.
*
diff --git a/newstore/RESTSession.ts b/newstore/RESTSession.ts
index 6593579dc..e6670a6f5 100644
--- a/newstore/RESTSession.ts
+++ b/newstore/RESTSession.ts
@@ -1,10 +1,11 @@
-import { pluck, distinctUntilChanged } from "rxjs/operators"
+import { pluck, distinctUntilChanged, map } from "rxjs/operators"
import DispatchingStore, { defineDispatchers } from "./DispatchingStore"
import {
HoppRESTHeader,
HoppRESTParam,
HoppRESTRequest,
} from "~/helpers/types/HoppRESTRequest"
+import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
function getParamsInURL(url: string): { key: string; value: string }[] {
const result: { key: string; value: string }[] = []
@@ -109,6 +110,7 @@ function updateURLParam(
type RESTSession = {
request: HoppRESTRequest
+ response: HoppRESTResponse | null
}
const defaultRESTSession: RESTSession = {
@@ -118,6 +120,7 @@ const defaultRESTSession: RESTSession = {
headers: [],
method: "GET",
},
+ response: null,
}
const dispatchers = defineDispatchers({
@@ -269,6 +272,27 @@ const dispatchers = defineDispatchers({
},
}
},
+ deleteAllHeaders(curr: RESTSession) {
+ return {
+ request: {
+ ...curr.request,
+ headers: [],
+ },
+ }
+ },
+ updateResponse(
+ _curr: RESTSession,
+ { updatedRes }: { updatedRes: HoppRESTResponse | null }
+ ) {
+ return {
+ response: updatedRes,
+ }
+ },
+ clearResponse(_curr: RESTSession) {
+ return {
+ response: null,
+ }
+ },
})
const restSessionStore = new DispatchingStore(defaultRESTSession, dispatchers)
@@ -354,6 +378,29 @@ export function deleteRESTHeader(index: number) {
})
}
+export function deleteAllRESTHeaders() {
+ restSessionStore.dispatch({
+ dispatcher: "deleteAllHeaders",
+ payload: {},
+ })
+}
+
+export function updateRESTResponse(updatedRes: HoppRESTResponse | null) {
+ restSessionStore.dispatch({
+ dispatcher: "updateResponse",
+ payload: {
+ updatedRes,
+ },
+ })
+}
+
+export function clearRESTResponse() {
+ restSessionStore.dispatch({
+ dispatcher: "clearResponse",
+ payload: {},
+ })
+}
+
export const restRequest$ = restSessionStore.subject$.pipe(
pluck("request"),
distinctUntilChanged()
@@ -369,7 +416,25 @@ export const restParams$ = restSessionStore.subject$.pipe(
distinctUntilChanged()
)
+export const restActiveParamsCount$ = restParams$.pipe(
+ map((params) => params.filter((x) => x.active).length)
+)
+
export const restMethod$ = restSessionStore.subject$.pipe(
pluck("request", "method"),
distinctUntilChanged()
)
+
+export const restHeaders$ = restSessionStore.subject$.pipe(
+ pluck("request", "headers"),
+ distinctUntilChanged()
+)
+
+export const restActiveHeadersCount$ = restHeaders$.pipe(
+ map((params) => params.filter((x) => x.active).length)
+)
+
+export const restResponse$ = restSessionStore.subject$.pipe(
+ pluck("response"),
+ distinctUntilChanged()
+)
diff --git a/newstore/environments.ts b/newstore/environments.ts
index 61a132f84..7d0321cff 100644
--- a/newstore/environments.ts
+++ b/newstore/environments.ts
@@ -1,4 +1,5 @@
-import { pluck } from "rxjs/operators"
+import { combineLatest } from "rxjs"
+import { map, pluck } from "rxjs/operators"
import DispatchingStore, {
defineDispatchers,
} from "~/newstore/DispatchingStore"
@@ -202,6 +203,24 @@ export const selectedEnvIndex$ = environmentsStore.subject$.pipe(
pluck("currentEnvironmentIndex")
)
+export const currentEnvironment$ = combineLatest([
+ environments$,
+ selectedEnvIndex$,
+]).pipe(
+ map(([envs, selectedIndex]) => {
+ if (selectedIndex === -1) {
+ const env: Environment = {
+ name: "No Environment",
+ variables: [],
+ }
+
+ return env
+ } else {
+ return envs[selectedIndex]
+ }
+ })
+)
+
export function getCurrentEnvironment(): Environment {
if (environmentsStore.value.currentEnvironmentIndex === -1) {
return {
diff --git a/package-lock.json b/package-lock.json
index e86cd945a..96f867402 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -33,7 +33,7 @@
"socketio-wildcard": "^2.0.0",
"splitpanes": "^2.3.6",
"tern": "^0.24.3",
- "three": "^0.130.0",
+ "three": "^0.130.1",
"three-globe": "^2.18.5",
"three-trackballcontrols": "^0.9.0",
"vue-apollo": "^3.0.7",
@@ -27994,9 +27994,9 @@
}
},
"node_modules/three": {
- "version": "0.130.0",
- "resolved": "https://registry.npmjs.org/three/-/three-0.130.0.tgz",
- "integrity": "sha512-4jqvbJyvgrjTsBgqE7TrdkZral78l8CXpFCdGzqQoiJHsRhGHxe5tvwqZQVaS6eodPav7jdYO5sp1c5RmMB3ng=="
+ "version": "0.130.1",
+ "resolved": "https://registry.npmjs.org/three/-/three-0.130.1.tgz",
+ "integrity": "sha512-OSPPKcGvFSiGkG3jFrwwC76PBV/ZSrGxpBbg28bW8s9GU8r/y2spNGtEXHEb/CVqo0Ctf5Lx2rVaxQZB6OasaA=="
},
"node_modules/three-conic-polygon-geometry": {
"version": "1.4.4",
@@ -55085,9 +55085,9 @@
}
},
"three": {
- "version": "0.130.0",
- "resolved": "https://registry.npmjs.org/three/-/three-0.130.0.tgz",
- "integrity": "sha512-4jqvbJyvgrjTsBgqE7TrdkZral78l8CXpFCdGzqQoiJHsRhGHxe5tvwqZQVaS6eodPav7jdYO5sp1c5RmMB3ng=="
+ "version": "0.130.1",
+ "resolved": "https://registry.npmjs.org/three/-/three-0.130.1.tgz",
+ "integrity": "sha512-OSPPKcGvFSiGkG3jFrwwC76PBV/ZSrGxpBbg28bW8s9GU8r/y2spNGtEXHEb/CVqo0Ctf5Lx2rVaxQZB6OasaA=="
},
"three-conic-polygon-geometry": {
"version": "1.4.4",
diff --git a/package.json b/package.json
index 20555fca2..e5015a9ed 100644
--- a/package.json
+++ b/package.json
@@ -49,7 +49,7 @@
"socketio-wildcard": "^2.0.0",
"splitpanes": "^2.3.6",
"tern": "^0.24.3",
- "three": "^0.130.0",
+ "three": "^0.130.1",
"three-globe": "^2.18.5",
"three-trackballcontrols": "^0.9.0",
"vue-apollo": "^3.0.7",
diff --git a/pages/index.vue b/pages/index.vue
index ecf46ed1a..a72ea65b7 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -5,259 +5,13 @@
-
+
@@ -348,20 +102,10 @@
-
+
@@ -860,12 +604,11 @@ import { getSettingSubject, applySetting } from "~/newstore/settings"
import { addRESTHistoryEntry } from "~/newstore/history"
import clone from "lodash/clone"
import {
- restMethod$,
- restEndpoint$,
restRequest$,
- setRESTEndpoint,
- updateRESTMethod,
+ restActiveParamsCount$,
+ restActiveHeadersCount$,
} from "~/newstore/RESTSession"
+import { map } from "rxjs/operators"
export default {
components: { Splitpanes, Pane },
@@ -896,27 +639,15 @@ export default {
showTokenRequestList: false,
showSaveRequestModal: false,
editRequest: {},
- customMethod: false,
files: [],
filenames: "",
- navigatorShare: navigator.share,
runningRequest: false,
currentMethodIndex: 0,
- methodMenuItems: [
- "GET",
- "HEAD",
- "POST",
- "PUT",
- "DELETE",
- "CONNECT",
- "OPTIONS",
- "TRACE",
- "PATCH",
- "CUSTOM",
- ],
- newEndpoint$: "",
- newMethod$: "",
+ newActiveParamsCount$: "",
+ newActiveHeadersCount$: "",
+
+ effectiveStream$: null,
}
},
subscriptions() {
@@ -927,14 +658,21 @@ export default {
EXPERIMENTAL_URL_BAR_ENABLED: getSettingSubject(
"EXPERIMENTAL_URL_BAR_ENABLED"
),
- newEndpoint$: restEndpoint$,
- newMethod$: restMethod$,
+ newActiveParamsCount$: restActiveParamsCount$.pipe(
+ map((e) => {
+ if (e == 0) return null
+ return e.toString()
+ })
+ ),
+ newActiveHeadersCount$: restActiveHeadersCount$.pipe(
+ map((e) => {
+ if (e == 0) return null
+ return e.toString()
+ })
+ ),
}
},
watch: {
- newEndpoint$(newVal) {
- setRESTEndpoint(newVal)
- },
canListParameters: {
immediate: true,
handler(canListParameters) {
@@ -1400,9 +1138,6 @@ export default {
},
},
methods: {
- updateMethod(method) {
- updateRESTMethod(method)
- },
scrollInto(view) {
this.$refs[view].$el.scrollIntoView({
behavior: "smooth",
@@ -1477,6 +1212,7 @@ export default {
cancelRequest() {
cancelRunningRequest()
},
+ newSendRequest() {},
async sendRequest() {
this.$toast.clear()
if (this.SCROLL_INTO_ENABLED) this.scrollInto("response")