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
feat: add header session store fields and dispatchers
Andrew Bastinffc891f38efc
diff --git a/helpers/types/HoppRESTRequest.ts b/helpers/types/HoppRESTRequest.tsindex f0ceced5f..cc7148005 100644--- a/helpers/types/HoppRESTRequest.ts+++ b/helpers/types/HoppRESTRequest.ts@@ -4,8 +4,15 @@ export type HoppRESTParam = {active: boolean}+export type HoppRESTHeader = {+ key: string+ value: string+ active: boolean+}+export interface HoppRESTRequest {method: stringendpoint: stringparams: HoppRESTParam[]+ headers: HoppRESTHeader[]}diff --git a/newstore/RESTSession.ts b/newstore/RESTSession.tsindex bd33e4f38..6593579dc 100644--- a/newstore/RESTSession.ts+++ b/newstore/RESTSession.ts@@ -1,6 +1,10 @@import { pluck, distinctUntilChanged } from "rxjs/operators"import DispatchingStore, { defineDispatchers } from "./DispatchingStore"-import { HoppRESTParam, HoppRESTRequest } from "~/helpers/types/HoppRESTRequest"+import {+ HoppRESTHeader,+ HoppRESTParam,+ HoppRESTRequest,+} from "~/helpers/types/HoppRESTRequest"function getParamsInURL(url: string): { key: string; value: string }[] {const result: { key: string; value: string }[] = []@@ -111,6 +115,7 @@ const defaultRESTSession: RESTSession = {request: {endpoint: "https://httpbin.org/",params: [],+ headers: [],method: "GET",},}@@ -234,6 +239,36 @@ const dispatchers = defineDispatchers({},}},+ addHeader(curr: RESTSession, { entry }: { entry: HoppRESTHeader }) {+ return {+ request: {+ ...curr.request,+ headers: [...curr.request.headers, entry],+ },+ }+ },+ updateHeader(+ curr: RESTSession,+ { index, updatedEntry }: { index: number; updatedEntry: HoppRESTHeader }+ ) {+ return {+ request: {+ ...curr.request,+ headers: curr.request.headers.map((header, i) => {+ if (i === index) return updatedEntry+ else return header+ }),+ },+ }+ },+ deleteHeader(curr: RESTSession, { index }: { index: number }) {+ return {+ request: {+ ...curr.request,+ headers: curr.request.headers.filter((_, i) => i !== index),+ },+ }+ },})const restSessionStore = new DispatchingStore(defaultRESTSession, dispatchers)@@ -291,6 +326,34 @@ export function updateRESTMethod(newMethod: string) {})}+export function addRESTHeader(entry: HoppRESTHeader) {+ restSessionStore.dispatch({+ dispatcher: "addHeader",+ payload: {+ entry,+ },+ })+}++export function updateRESTHeader(index: number, updatedEntry: HoppRESTHeader) {+ restSessionStore.dispatch({+ dispatcher: "updateHeader",+ payload: {+ index,+ updatedEntry,+ },+ })+}++export function deleteRESTHeader(index: number) {+ restSessionStore.dispatch({+ dispatcher: "deleteHeader",+ payload: {+ index,+ },+ })+}+export const restRequest$ = restSessionStore.subject$.pipe(pluck("request"),distinctUntilChanged()