MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / requestJson

Function requestJson

apps/cli/scripts/smoke-packed-apps.ts:17–29  ·  view source on GitHub ↗
(origin: string, path: string, init: RequestInit = {})

Source from the content-addressed store, hash-verified

15};
16
17const requestJson = async <T>(origin: string, path: string, init: RequestInit = {}): Promise<T> => {
18 const response = await fetch(new URL(path, origin), {
19 ...init,
20 headers: {
21 authorization: `Bearer ${AUTH_TOKEN}`,
22 ...(init.body === undefined ? {} : { "content-type": "application/json" }),
23 ...init.headers,
24 },
25 });
26 const text = await response.text();
27 if (!response.ok) fail(`${init.method ?? "GET"} ${path} returned ${response.status}: ${text}`);
28 return (text.length > 0 ? JSON.parse(text) : null) as T;
29};
30
31const waitForReadyPort = async (proc: Subprocess<"ignore", "pipe", "pipe">): Promise<number> =>
32 new Promise((resolveReady, rejectReady) => {

Callers 1

mainFunction · 0.85

Calls 3

failFunction · 0.70
textMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected