From 82e03978b89938219958032efb1448cc76baa181 Mon Sep 17 00:00:00 2001 From: Saumit Date: Sat, 27 Sep 2025 02:14:26 +0530 Subject: Initial snapshot - OpenTelemetry demo 2.1.3 -f --- src/react-native-app/utils/Request.ts | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/react-native-app/utils/Request.ts (limited to 'src/react-native-app/utils/Request.ts') diff --git a/src/react-native-app/utils/Request.ts b/src/react-native-app/utils/Request.ts new file mode 100644 index 0000000..77fadc8 --- /dev/null +++ b/src/react-native-app/utils/Request.ts @@ -0,0 +1,41 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 +/** + * Copied with modification from src/frontend/utils/Request.ts + */ +import getFrontendProxyURL from "@/utils/Settings"; + +interface IRequestParams { + url: string; + body?: object; + method?: "GET" | "POST" | "PUT" | "DELETE"; + queryParams?: Record; + headers?: Record; +} + +const request = async ({ + url = "", + method = "GET", + body, + queryParams = {}, + headers = { + "content-type": "application/json", + }, +}: IRequestParams): Promise => { + const proxyURL = await getFrontendProxyURL(); + const requestURL = `${proxyURL}${url}?${new URLSearchParams(queryParams).toString()}`; + const requestBody = body ? JSON.stringify(body) : undefined; + const response = await fetch(requestURL, { + method, + body: requestBody, + headers, + }); + + const responseText = await response.text(); + + if (!!responseText) return JSON.parse(responseText); + + return undefined as unknown as T; +}; + +export default request; -- cgit v1.2.3